Skip to content

Commit 8c4f675

Browse files
committed
refactor(material-experimental/theming): align autocomplete with M3 spec
Aligns the autocomplete with the M3 spec by tokenizing the elevation and container shape.
1 parent 1dcc195 commit 8c4f675

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

src/dev-app/autocomplete/autocomplete-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="demo-autocomplete">
44
<mat-card>
55
Reactive length: {{ reactiveStates.length }}
6-
<div>Reactive value: {{ stateCtrl.value | json }}</div>
6+
<div class="demo-truncate-text">Reactive value: {{ stateCtrl.value | json }}</div>
77
<div>Reactive dirty: {{ stateCtrl.dirty }}</div>
88

99
<mat-form-field [color]="reactiveStatesTheme">

src/dev-app/autocomplete/autocomplete-demo.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@
1919
color: rgba(0, 0, 0, 0.54);
2020
margin-left: 8px;
2121
}
22+
23+
.demo-truncate-text {
24+
white-space: nowrap;
25+
overflow: hidden;
26+
text-overflow: ellipsis;
27+
}

src/material-experimental/theming/_custom-tokens.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@use 'sass:map';
22
@use '@angular/material' as mat;
3+
@use '@material/elevation/elevation-theme' as mdc-elevation;
34

45
/// Hardcode the given value, or null if hardcoded values are excluded.
56
@function _hardcode($value, $exclude-hardcoded) {
@@ -28,6 +29,9 @@
2829
@function autocomplete($systems, $exclude-hardcoded) {
2930
@return (
3031
background-color: map.get($systems, md-sys-color, surface-container),
32+
container-shape: map.get($systems, md-sys-shape, corner-extra-small),
33+
container-elevation-shadow:
34+
_hardcode(mdc-elevation.elevation-box-shadow(2), $exclude-hardcoded),
3135
);
3236
}
3337

src/material/autocomplete/_autocomplete-theme.scss

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
@if inspection.get-theme-version($theme) == 1 {
1111
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
1212
}
13-
@else {}
13+
@else {
14+
@include sass-utils.current-selector-or-root() {
15+
@include token-utils.create-token-values(tokens-mat-autocomplete.$prefix,
16+
tokens-mat-autocomplete.get-unthemable-tokens());
17+
}
18+
}
1419
}
1520

1621
@mixin color($theme) {
@@ -29,14 +34,24 @@
2934
@if inspection.get-theme-version($theme) == 1 {
3035
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
3136
}
32-
@else {}
37+
@else {
38+
@include sass-utils.current-selector-or-root() {
39+
@include token-utils.create-token-values(tokens-mat-autocomplete.$prefix,
40+
tokens-mat-autocomplete.get-typography-tokens($theme));
41+
}
42+
}
3343
}
3444

3545
@mixin density($theme) {
3646
@if inspection.get-theme-version($theme) == 1 {
3747
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
3848
}
39-
@else {}
49+
@else {
50+
@include sass-utils.current-selector-or-root() {
51+
@include token-utils.create-token-values(tokens-mat-autocomplete.$prefix,
52+
tokens-mat-autocomplete.get-density-tokens($theme));
53+
}
54+
}
4055
}
4156

4257
@mixin theme($theme) {

src/material/autocomplete/autocomplete.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
@use '@angular/cdk';
2-
@use '../core/style/elevation';
32
@use '../core/tokens/token-utils';
43
@use '../core/tokens/m2/mat/autocomplete' as tokens-mat-autocomplete;
54

65
// Even though we don't use the MDC styles, we need to keep the classes in the
76
// DOM for the Gmat versions to work. We need to bump up the specificity here
87
// so that it's higher than MDC's styles.
98
div.mat-mdc-autocomplete-panel {
10-
@include elevation.elevation(8);
119
width: 100%; // Ensures that the panel matches the overlay width.
1210
max-height: 256px; // Prevents lists with a lot of option from growing too high.
1311
visibility: hidden;
1412
transform-origin: center top;
1513
overflow: auto;
1614
padding: 8px 0;
17-
border-radius: 4px;
1815
box-sizing: border-box;
1916

2017
// Workaround in case other MDC menu surface styles bleed in.
2118
position: static;
2219

2320
@include token-utils.use-tokens(
2421
tokens-mat-autocomplete.$prefix, tokens-mat-autocomplete.get-token-slots()) {
22+
@include token-utils.create-token-slot(border-radius, container-shape);
23+
@include token-utils.create-token-slot(box-shadow, container-elevation-shadow);
2524
@include token-utils.create-token-slot(background-color, background-color);
2625
}
2726

src/material/core/tokens/m2/mat/_autocomplete.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use '@material/elevation/elevation-theme' as mdc-elevation;
12
@use '../../token-utils';
23
@use '../../../theming/inspection';
34
@use '../../../style/sass-utils';
@@ -8,7 +9,10 @@ $prefix: (mat, autocomplete);
89
// Tokens that can't be configured through Angular Material's current theming API,
910
// but may be in a future version of the theming API.
1011
@function get-unthemable-tokens() {
11-
@return ();
12+
@return (
13+
container-shape: 4px,
14+
container-elevation-shadow: mdc-elevation.elevation-box-shadow(8),
15+
);
1216
}
1317

1418
// Tokens that can be configured through Angular Material's color theming API.

0 commit comments

Comments
 (0)