Skip to content

Full grids don't follow runtime theme switches from the docs theming widget #1310

Description

@IMinchev64

Description

When a sample is embedded in the docs and the theme is switched with the docs theming widget, the full grids (IgbGrid, IgbTreeGrid, IgbHierarchicalGrid, IgbPivotGrid and the other components built on Angular Elements) only partly follow the new theme.

The grid stylesheet (_content/IgniteUI.Blazor/themes/grid/<mode>/<theme>.css) is swapped by sample-theme.js, so colors and CSS-variable-driven sizing change. The grid's internal theme does not: the parts that render per theme (for example the input groups in filtering and editing) keep the theme the grid was created with. The grid ends up mixing the new theme's CSS with the old theme's structure.

The web components (IgbInput, IgbButton, …) and GridLite are handled by #1308; the full grids are not covered by it (or by #1307).

Cause

The Angular Elements grids read their theme from a single root ThemeToken, created once when the first grid is built. It reads --ig-theme from document.body at that moment and is never updated afterwards:

// ThemeToken constructor in the igniteui-angular-elements bundle shipped with
// IgniteUI.Blazor 26.1.98 (de-minified)
const fromCss = globalThis.window?.getComputedStyle(this.document.body).getPropertyValue("--ig-theme").trim() || "material";
this.subject = new BehaviorSubject(explicitTheme ?? fromCss);

Theme-dependent grid internals subscribe to it (themeToken.onChange(...)), so calling its set() would update them, but nothing public reaches it: it isn't exposed by IgniteUI.Blazor, IgbGrid has no theme parameter, and the grids bundle doesn't listen for igc-change-theme or the web components' theme context.

The same limitation applies to the grid theme-switching sample in #1240, which also only swaps the grid stylesheet.

Steps to reproduce

  1. Run the Blazor samples browser and the docs locally.
  2. Open a docs grid topic whose sample has the theme picker enabled.
  3. Switch the theme, e.g. Bootstrap → Material.
  4. Open filtering or editing in the grid: the input groups keep Bootstrap's structure under Material's CSS.

A grid created after a switch picks up the new theme correctly, since the token reads --ig-theme at creation.

Possible fixes

  • Upstream (preferred): make the Angular Elements ThemeToken follow runtime theme changes, e.g. re-read --ig-theme when the global igc-change-theme event fires (what configureTheme() dispatches). sample-theme.js would then dispatch that event after the stylesheets are swapped. This would fix runtime theme switching for grids in every Blazor app, not just the samples browser.
  • Workaround in the samples browser: for pages that contain Angular Elements components, reload the sample when the theme changes, passing the selection across the reload (e.g. sessionStorage keyed by location.pathname) and applying it in <head> before Blazor starts, so the grids read the right --ig-theme when they are created. Costs a Blazor restart per switch and loses the sample's state (sorting, filtering, scroll position), on grid pages only.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: in-browserrelated to code of sample browser

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions