Skip to content

feat(themes)!: default the global rules to :root, :scope, :host and add configure-root-selector() - #680

Open
simeonoff wants to merge 3 commits into
simeonoff/mcp-theme-entry-pointfrom
simeonoff/root-selector
Open

simeonoff wants to merge 3 commits into
simeonoff/mcp-theme-entry-pointfrom
simeonoff/root-selector

Conversation

@simeonoff

@simeonoff simeonoff commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Part of #651, section 5. Stacked on #679, which is stacked on #677. Ships in a major.

  • The global mixins (theme(), typography(), palette(), elevations(), the global tokens(), chart-themes()) write to :root, :scope, :host at the top level, so a theme also applies inside @scope and in a shadow root. In a document it matches the same element as :root, with the same specificity.
  • typography() puts the .ig-typography rules on the scoping root, an ancestor outside it, and the host. The scope selectors are in :where(), so overrides of .ig-typography h1 still win. On the host, the class goes inside the :host() argument (:host(:where(.ig-typography)) h1), with the same specificity as .ig-typography h1, so an element reset in the shadow root doesn't override it. A :host(...) root selector such as :host(.dark) gets the class in its argument.
  • configure-root-selector(':root') restores the previous output.
  • typography() inside :host now emits matching class selectors.
  • MCP: set_size, set_spacing and set_roundness default to the same selector, the chart theme example includes tokens() at the top level, and the tool descriptions and docs describe the new output.

Breaking:

  • In an Angular component stylesheet with emulated encapsulation, a global mixin at the top level now themes the component's host and its subtree, where it emitted nothing before. For example, the Angular CLI fintech tree grid and fintech grid templates call core() and typography() at the top level of their component stylesheet, and the tree grid also calls theme($default-palette). In an app with a custom theme, those components switch to the Material typography, and the tree grid also to the default Material palette. Remove the top-level typography() and theme() calls when the global stylesheet already includes them. core() can stay: it doesn't change the theme on the host, and other theme mixins in the same stylesheet may need it (Remove the global theme mixins from the fintech grid and fintech tree grid component styles igniteui-cli#1909, fix(angular): remove the global typography and theme from the fintech grid templates igniteui-cli#1910).
  • In a shadow root whose stylesheet includes typography() at the top level, a host with the ig-typography class now gets the heading and paragraph styles, where it got none before. They win over element and single-class rules on those elements, as .ig-typography h1 does in the document.

Checked before and after:

  • Compiled output of igniteui-angular (themes, Elements grid themes), igniteui-webcomponents (themes, component styles) and both sample repos.
  • Web Components and the Elements grid rendered in Chromium, Firefox and WebKit.
  • All prerendered routes of the Angular samples.

The only rendering change was the top-level tokens() in two emulated stepper samples, which now applies.

@simeonoff
simeonoff force-pushed the simeonoff/root-selector branch from 9e011a6 to d52378c Compare November 16, 2026 14:33
…dd configure-root-selector()

At the top level, the global mixins write to :root, :scope, :host instead of :root, so a theme applies in the document, inside @scope and in a shadow root. In a document it matches the same element as :root, with the same specificity. The extra .ig-typography selectors are in :where(), so their specificity doesn't change. chart-themes() uses the same selector.

typography() inside :host now emits matching class selectors.

BREAKING CHANGE: in an Angular component stylesheet with emulated encapsulation, a global mixin at the top level, such as tokens(), palette(), core() or theme(), now themes the component's host and its subtree, where it emitted nothing before. Use configure-root-selector(':root') to keep the previous output.
…d guidance

set_size, set_spacing and set_roundness default to :root, :scope, :host, the selector the themes now use, so their overrides also apply inside @scope and in a shadow root. The chart theme example includes tokens() at the top level instead of inside :root. The tool descriptions and docs describe the new output, and the spacing() output example registers the property at the top level.
@simeonoff
simeonoff force-pushed the simeonoff/root-selector branch from d52378c to 3c68f0a Compare November 16, 2026 14:46
@simeonoff
simeonoff changed the base branch from simeonoff/theme-entry-point to simeonoff/mcp-theme-entry-point November 16, 2026 14:46

@desig9stein desig9stein left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Simeon. The stack does what #651 asked for, and existing apps are safe.

What I checked

  • Every stylesheet that uses theming in our 12 repos, compiled before and after the stack. Nothing new fails, and the only output change is the new :root, :scope, :host selector.
  • Our shipped theme files in the browser: the Web Components themes, the Angular presets and the grid themes. Colors, fonts and shadows are the same before and after, in Chromium, Firefox and WebKit.
  • Rendering changes in the samples. Only the two stepper samples in angular-samples look different, as you said.
  • The repos' own checks. The igniteui-angular Sass tests pass

The one thing to fix before merging is in #681, see my review there. Here there are two typography fixes, a note for the breaking change, and two small items.

1. Headings in a shadow root lose to a simple reset

I see why the island selectors are wrapped in :where(). Inside @scope, the theme would otherwise beat a user's own .ig-typography h1 override. I measured that, and your version is right there.

A shadow root has no such priority, so the :where() only makes the theme weaker there. If the shadow root has a common reset like h1 { font-size: inherit }, the heading drops from 96px to 16px. The page itself keeps 96px. This is the same in all three browsers.

Keeping the class outside :where() for the host case fixes it and changes nothing else (typography/_mixins.scss:177):

:host(:where(.ig-typography)) h1

2. :host(.dark) as the root selector gets no typography

configure-root-selector() accepts any selector, but the typography only recognizes a plain :host (_mixins.scss:162). With configure-root-selector(':host(.dark)') and a host with class="dark ig-typography", the colors apply but the typography doesn't. The heading is 32px instead of 96px, and .ig-typography__h1 is 16px, in all three browsers.

Please handle :host(...) the same way as :host, for example as :host(:where(.dark.ig-typography)) h1, and add a test for it.

3. For the breaking change note

The breaking change you described has one real case outside the sample repos. The Angular CLI "fintech tree grid" template has these lines in its component stylesheet (cli packages/igx-templates/igx-ts/custom-templates/fintech-tree-grid/files/src/app/__path__/__filePrefix__.scss:207-209):

@include core();
@include typography($font-family: $material-typeface, $type-scale: $material-type-scale);
@include theme($default-palette);

Until now they did nothing for the component. After this PR, in an app generated with a custom theme, that component switches to the default Material palette: its secondary color turns from the app's blue to pink. The rest of the page doesn't change.

Please name this case in the breaking change note. Could you also open an issue in the CLI repo, with a PR that removes these three lines from the template? The app's global styles already include them, so the component keeps the app's theme after this PR.

4. Small fixes

  • The MCP README still says the layout tools default to :root (packages/mcp/README.md, lines 441, 463, 483 and 723). They now use :root, :scope, :host.
  • The chart colors snippet doesn't compile. You edited it in knowledge/docs/colors/chart-series.md, and the same snippet is returned by get_chart_series_colors (tools/handlers/chart-colors.ts:262). It fails with "Undefined mixin" because igniteui-theming/sass/themes/charts doesn't include tokens(). It was already broken on master. Adding @use 'igniteui-theming/sass/themes' as *; fixes it.

…electors

Inside a shadow root, the typography rules put the class inside :host() instead of wrapping :host in :where(), so an element reset like h1 { font-size: inherit } no longer overrides them. A :host(...) root selector now gets the class in its argument, so configure-root-selector(':host(.dark)') applies the typography. The MCP README states the :root, :scope, :host default, and the chart colors snippet now loads tokens().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants