Repository navigation
feat(themes)!: default the global rules to :root, :scope, :host and add configure-root-selector() - #680
feat(themes)!: default the global rules to :root, :scope, :host and add configure-root-selector()#680simeonoff wants to merge 3 commits into
Conversation
9e011a6 to
d52378c
Compare
…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.
d52378c to
3c68f0a
Compare
There was a problem hiding this comment.
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, :hostselector. - 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)) h12. :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 byget_chart_series_colors(tools/handlers/chart-colors.ts:262). It fails with "Undefined mixin" becauseigniteui-theming/sass/themes/chartsdoesn't includetokens(). It was already broken onmaster. 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().
Part of #651, section 5. Stacked on #679, which is stacked on #677. Ships in a major.
theme(),typography(),palette(),elevations(), the globaltokens(),chart-themes()) write to:root, :scope, :hostat the top level, so a theme also applies inside@scopeand in a shadow root. In a document it matches the same element as:root, with the same specificity.typography()puts the.ig-typographyrules on the scoping root, an ancestor outside it, and the host. The scope selectors are in:where(), so overrides of.ig-typography h1still 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:hostnow emits matching class selectors.set_size,set_spacingandset_roundnessdefault to the same selector, the chart theme example includestokens()at the top level, and the tool descriptions and docs describe the new output.Breaking:
core()andtypography()at the top level of their component stylesheet, and the tree grid also callstheme($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-leveltypography()andtheme()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).typography()at the top level, a host with theig-typographyclass 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 h1does in the document.Checked before and after:
The only rendering change was the top-level
tokens()in two emulated stepper samples, which now applies.