Skip to content

Commit 1a1929d

Browse files
authored
docs: Add better documentation and errors regarding including theme mixins at root (#28593)
1 parent cb3192d commit 1a1929d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+139
-1
lines changed

guides/material-3.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ well.
339339
### Update usages of APIs that are not supported for Material 3 themes
340340
Because Material 3 is implemented as an alternate theme for the same components used for Material 2,
341341
the APIs for both are largely the same. However, there are a few differences to be aware of:
342+
- M3 expects that any `@include` of the `-theme`, `-color`, `-typography`, `-density`, or `-base`
343+
mixins should be wrapped in a selector. If your app includes such an `@include` at the root level,
344+
we recommend wrapping it in `html { ... }`
342345
- M3 has a different API for setting the color variant of a component (see
343346
[using component color variants](#using-component-color-variants) for more).
344347
- The `backgroundColor` property of `<mat-tab-group>` is not supported, and should not be used with

src/material/autocomplete/_autocomplete-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@use 'sass:map';
22
@use '../core/theming/theming';
33
@use '../core/theming/inspection';
4+
@use '../core/theming/validation';
45
@use '../core/typography/typography';
56
@use '../core/style/sass-utils';
67
@use '../core/tokens/token-utils';
@@ -75,6 +76,8 @@
7576
}
7677

7778
@mixin _theme-from-tokens($tokens) {
79+
@include validation.selector-defined(
80+
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
7881
@if ($tokens != ()) {
7982
@include token-utils.create-token-values(
8083
tokens-mat-autocomplete.$prefix, map.get($tokens, tokens-mat-autocomplete.$prefix));

src/material/badge/_badge-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@use 'sass:color';
22
@use '../core/theming/theming';
33
@use '../core/theming/inspection';
4+
@use '../core/theming/validation';
45
@use '../core/typography/typography';
56
@use '../core/tokens/m2/mat/badge' as tokens-mat-badge;
67
@use '../core/tokens/token-utils';
@@ -97,6 +98,8 @@
9798
}
9899

99100
@mixin _theme-from-tokens($tokens, $options...) {
101+
@include validation.selector-defined(
102+
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
100103
$mat-badge-tokens: token-utils.get-tokens-for($tokens, tokens-mat-badge.$prefix, $options...);
101104
@include token-utils.create-token-values(tokens-mat-badge.$prefix, $mat-badge-tokens);
102105
}

src/material/bottom-sheet/_bottom-sheet-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@use '../core/typography/typography';
33
@use '../core/theming/theming';
44
@use '../core/theming/inspection';
5+
@use '../core/theming/validation';
56
@use '../core/style/sass-utils';
67
@use '../core/tokens/token-utils';
78
@use '../core/tokens/m2/mat/bottom-sheet' as tokens-mat-bottom-sheet;
@@ -70,6 +71,8 @@
7071
}
7172

7273
@mixin _theme-from-tokens($tokens) {
74+
@include validation.selector-defined(
75+
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
7376
@if ($tokens != ()) {
7477
@include token-utils.create-token-values(
7578
tokens-mat-bottom-sheet.$prefix, map.get($tokens, tokens-mat-bottom-sheet.$prefix));

src/material/button-toggle/_button-toggle-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@use '../core/theming/theming';
22
@use '../core/theming/inspection';
3+
@use '../core/theming/validation';
34
@use '../core/typography/typography';
45
@use '../core/tokens/m2/mat/legacy-button-toggle' as tokens-mat-legacy-button-toggle;
56
@use '../core/tokens/m2/mat/standard-button-toggle' as tokens-mat-standard-button-toggle;
@@ -104,6 +105,8 @@
104105
}
105106

106107
@mixin _theme-from-tokens($tokens, $options...) {
108+
@include validation.selector-defined(
109+
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
107110
$mat-standard-button-toggle-tokens:
108111
token-utils.get-tokens-for($tokens, tokens-mat-standard-button-toggle.$prefix, $options...);
109112
@include token-utils.create-token-values(

src/material/button/_button-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
@use '../core/theming/theming';
77
@use '../core/theming/inspection';
8+
@use '../core/theming/validation';
89
@use '../core/tokens/token-utils';
910
@use '../core/typography/typography';
1011
@use '../core/tokens/m2/mdc/filled-button' as tokens-mdc-filled-button;
@@ -78,6 +79,8 @@
7879
}
7980

8081
@mixin _theme-from-tokens($tokens, $options...) {
82+
@include validation.selector-defined(
83+
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
8184
$mdc-text-button-tokens:
8285
token-utils.get-tokens-for($tokens, tokens-mdc-text-button.$prefix, $options...);
8386
$mdc-protected-button-tokens:

src/material/button/_fab-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@use '../core/style/sass-utils';
55
@use '../core/theming/theming';
66
@use '../core/theming/inspection';
7+
@use '../core/theming/validation';
78
@use '../core/tokens/m2/mdc/fab' as tokens-mdc-fab;
89
@use '../core/tokens/m2/mdc/fab-small' as tokens-mdc-fab-small;
910
@use '../core/tokens/m2/mdc/extended-fab' as tokens-mdc-extended-fab;
@@ -166,6 +167,8 @@
166167
}
167168

168169
@mixin _theme-from-tokens($tokens, $options...) {
170+
@include validation.selector-defined(
171+
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
169172
$mdc-extended-fab-tokens: token-utils.get-tokens-for(
170173
$tokens, tokens-mdc-extended-fab.$prefix, $options...);
171174
$mdc-fab-tokens: token-utils.get-tokens-for($tokens, tokens-mdc-fab.$prefix, $options...);

src/material/button/_icon-button-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@use '../core/tokens/token-utils';
99
@use '../core/theming/theming';
1010
@use '../core/theming/inspection';
11+
@use '../core/theming/validation';
1112

1213

1314
@mixin base($theme) {
@@ -141,6 +142,8 @@
141142
}
142143

143144
@mixin _theme-from-tokens($tokens) {
145+
@include validation.selector-defined(
146+
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
144147
@if ($tokens != ()) {
145148
@include mdc-icon-button-theme.theme(map.get($tokens, tokens-mdc-icon-button.$prefix));
146149
@include token-utils.create-token-values(

src/material/card/_card-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@use '../core/style/sass-utils';
33
@use '../core/theming/theming';
44
@use '../core/theming/inspection';
5+
@use '../core/theming/validation';
56
@use '../core/typography/typography';
67
@use '../core/tokens/token-utils';
78
@use '../core/tokens/m2/mat/card' as tokens-mat-card;
@@ -108,6 +109,8 @@
108109
}
109110

110111
@mixin _theme-from-tokens($tokens) {
112+
@include validation.selector-defined(
113+
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
111114
@if ($tokens != ()) {
112115
$elevated-card-tokens: map.get($tokens, tokens-mdc-elevated-card.$prefix);
113116
// Work around a bug in MDC where the elevation is not resolved to an actual shadow value.

src/material/checkbox/_checkbox-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@use '../core/style/sass-utils';
44
@use '../core/theming/theming';
55
@use '../core/theming/inspection';
6+
@use '../core/theming/validation';
67
@use '../core/tokens/token-utils';
78
@use '../core/typography/typography';
89
@use '../core/tokens/m2/mdc/checkbox' as tokens-mdc-checkbox;
@@ -117,6 +118,8 @@
117118
}
118119

119120
@mixin _theme-from-tokens($tokens, $options...) {
121+
@include validation.selector-defined(
122+
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
120123
$mdc-checkbox-tokens: token-utils.get-tokens-for(
121124
$tokens, tokens-mdc-checkbox.$prefix, $options...);
122125
// Don't pass $options here, since the mdc-form-field doesn't support color options,

0 commit comments

Comments
 (0)