Skip to content

Commit 064d352

Browse files
committed
Use :host in root selectors so Web Components can access CSS vars
Reproduce #37162 on v6-dev. Adds `:host` beside every `:root` selector that emits CSS custom properties, so components styled in a shadow root see the tokens.
1 parent 4bacc48 commit 064d352

6 files changed

Lines changed: 16 additions & 8 deletions

File tree

scss/_colors.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ $-color-defaults: () !default;
9797
$color-tokens: defaults($-color-defaults, $color-tokens);
9898
// scss-docs-end color-tokens
9999

100-
:root {
100+
:root,
101+
:host {
101102
@include tokens($color-tokens);
102103
}

scss/_root.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ $root-tokens: map.set($root-tokens, --radius-pill, 50rem);
198198
$root-tokens: map.set($root-tokens, --z-#{$key}, $value);
199199
}
200200

201-
:root {
201+
:root,
202+
:host {
202203
@include tokens($root-tokens);
203204

204205
color-scheme: light dark;
@@ -210,7 +211,8 @@ $root-tokens: map.set($root-tokens, --radius-pill, 50rem);
210211
// Deepen shadows in dark mode. The shadow-strength token is a plain number, so it
211212
// can't use light-dark() (colors only); vary it alongside color-scheme instead.
212213
@media (prefers-color-scheme: dark) {
213-
:root {
214+
:root,
215+
:host {
214216
--shadow-strength: 2.4;
215217
}
216218
}

scss/bootstrap-grid.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ $utilities: map-get-multiple(
6161
// check-unused-imports-disable-next-line — side-effect import: generates utility CSS.
6262
@use "utilities/api";
6363

64-
:root {
64+
:root,
65+
:host {
6566
@each $name, $value in $breakpoints {
6667
--breakpoint-#{$name}: #{$value};
6768
}

scss/content/_reboot.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ $type-tokens: defaults(
2727
);
2828
// scss-docs-end type-tokens
2929

30-
:root {
30+
:root,
31+
:host {
3132
@include tokens($type-tokens);
3233
}
3334

@@ -81,7 +82,8 @@ $reboot-mark-tokens: defaults(
8182
// Ability to the value of the root font sizes, affecting the value of `rem`.
8283
// null by default, thus nothing is generated.
8384

84-
:root {
85+
:root,
86+
:host {
8587
// Assume browser default font-size of 16px, or a user's preference
8688
accent-color: var(--primary-base);
8789

scss/mixins/_color-mode.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
@if $color-mode-type == "media-query" {
66
@if $root == true {
77
@media (prefers-color-scheme: $mode) {
8-
:root {
8+
:root,
9+
:host {
910
@content;
1011
}
1112
}

scss/tests/mixins/_color-mode-media-query.test.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
}
2828
}
2929
@media (prefers-color-scheme: dark) {
30-
:root {
30+
:root,
31+
:host {
3132
--custom-color: #{color.mix($indigo, $blue, 50%, oklch)};
3233
}
3334
}

0 commit comments

Comments
 (0)