Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit aa5ac7f

Browse files
codrcopybara-github
authored andcommitted
fix(select): update text field in select to accept dynamic shape and height
PiperOrigin-RevId: 534105325
1 parent 19bb36a commit aa5ac7f

File tree

3 files changed

+93
-27
lines changed

3 files changed

+93
-27
lines changed

packages/mdc-select/_select-filled-theme.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,14 @@ $custom-property-prefix: 'filled-select';
157157

158158
@mixin theme-styles($theme, $resolvers: resolvers.$material) {
159159
@include theme.validate-theme-styles($_light-theme, $theme);
160-
$unprocessed-theme: $theme;
161160
$theme: select-shared-theme.resolve-theme($theme, $resolvers);
162161
$theme: keys.create-theme-properties(
163162
$theme,
164163
$prefix: $custom-property-prefix
165164
);
166165
@include select-theme.theme-styles($theme, $resolvers: $resolvers);
167166

168-
@include _container-height-and-shape($unprocessed-theme);
169-
}
170-
171-
@mixin _container-height-and-shape($theme) {
172167
@if map.get($theme, text-field-container-height) {
173-
// Note: This is not dynamic because this token is planned to be removed.
174-
// see b/242856144 and b/244747640
175168
@include select-theme.filled-height(
176169
map.get($theme, text-field-container-height)
177170
);

packages/mdc-select/_select-outlined-theme.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,14 @@ $custom-property-prefix: 'outlined-select';
159159

160160
@mixin theme-styles($theme, $resolvers: resolvers.$material) {
161161
@include theme.validate-theme-styles($_light-theme, $theme);
162-
$unprocessed-theme: $theme;
163162
$theme: select-shared-theme.resolve-theme($theme, $resolvers);
164163
$theme: keys.create-theme-properties(
165164
$theme,
166165
$prefix: $custom-property-prefix
167166
);
168167
@include select-theme.theme-styles($theme, $resolvers: $resolvers);
169168

170-
@include _container-height-and-shape($unprocessed-theme);
171-
}
172-
173-
@mixin _container-height-and-shape($theme) {
174169
@if map.get($theme, text-field-container-height) {
175-
// Note: This is not dynamic because this token is planned to be removed.
176-
// see b/242856144 and b/244747640
177170
@include select-theme.outlined-height(
178171
map.get($theme, text-field-container-height)
179172
);

packages/mdc-select/_select-theme.scss

Lines changed: 93 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
@use '@material/rtl/rtl';
4747
@use '@material/shape/functions' as shape-functions;
4848
@use '@material/shape/mixins' as shape-mixins;
49+
@use '@material/theme/css';
4950
@use '@material/theme/custom-properties';
5051
@use '@material/theme/gss';
5152
@use '@material/theme/keys';
@@ -61,8 +62,16 @@
6162
$ripple-target: '.mdc-select__ripple';
6263

6364
@function get-outlined-label-position-y($select-anchor-height) {
64-
@return math.div($select-anchor-height, 2) +
65-
math.div(notched-outline-variables.$label-box-height, 2);
65+
@if custom-properties.is-custom-prop($select-anchor-height) {
66+
$value: custom-properties.get-declaration-value($select-anchor-height);
67+
@return calc(
68+
calc($value / 2) +
69+
math.div(notched-outline-variables.$label-box-height, 2)
70+
);
71+
} @else {
72+
@return math.div($select-anchor-height, 2) +
73+
math.div(notched-outline-variables.$label-box-height, 2);
74+
}
6675
}
6776

6877
$arrow-padding: 52px !default;
@@ -855,7 +864,8 @@ $error-color: error !default;
855864
$rtl-reflexive: false,
856865
$query: feature-targeting.all()
857866
) {
858-
@if (meta.type-of($radius) == 'list' and list.length($radius) > 2) and
867+
@if (meta.type-of($radius) == 'list') and
868+
(list.length($radius) > 2) and
859869
(
860870
(list.nth($radius, 3) != 0 and list.nth($radius, 3) != 0px) or
861871
(list.nth($radius, 4) != 0 and list.nth($radius, 4) != 0px)
@@ -872,6 +882,42 @@ $error-color: error !default;
872882

873883
$masked-radius: shape-functions.mask-radius($radius, 1 1 0 0);
874884

885+
$fallback: if(
886+
custom-properties.is-custom-prop($radius),
887+
custom-properties.get-fallback($radius),
888+
null
889+
);
890+
891+
@if meta.type-of($fallback) == 'list' {
892+
$fallback: css.unpack-value($fallback);
893+
$first: list.nth($masked-radius, 1);
894+
$second: list.nth($masked-radius, 2);
895+
$third: list.nth($masked-radius, 3);
896+
$fourth: list.nth($masked-radius, 4);
897+
$masked-radius: (
898+
if(
899+
custom-properties.is-custom-prop($first),
900+
custom-properties.set-fallback($first, list.nth($fallback, 1)),
901+
$first
902+
),
903+
if(
904+
custom-properties.is-custom-prop($second),
905+
custom-properties.set-fallback($second, list.nth($fallback, 2)),
906+
$second
907+
),
908+
if(
909+
custom-properties.is-custom-prop($third),
910+
custom-properties.set-fallback($third, list.nth($fallback, 3)),
911+
$third
912+
),
913+
if(
914+
custom-properties.is-custom-prop($fourth),
915+
custom-properties.set-fallback($fourth, list.nth($fallback, 4)),
916+
$fourth
917+
)
918+
);
919+
}
920+
875921
.mdc-select__anchor {
876922
@include shape-mixins.radius(
877923
$masked-radius,
@@ -1108,7 +1154,7 @@ $error-color: error !default;
11081154

11091155
.mdc-select__anchor {
11101156
@include feature-targeting.targets($feat-structure) {
1111-
height: $new-height;
1157+
@include theme.property(height, $new-height);
11121158
}
11131159

11141160
// Filled variant is aligned to baseline...
@@ -1118,7 +1164,8 @@ $error-color: error !default;
11181164
$query: $query
11191165
);
11201166
// ...unless it is too small to display a label
1121-
@if $new-height < $minimum-height-for-filled-label {
1167+
// TODO(b/283457421): Account for dynamic height
1168+
@if _is-less-than($new-height, $minimum-height-for-filled-label) {
11221169
@include center-aligned($query: $query);
11231170

11241171
@include feature-targeting.targets($feat-structure) {
@@ -1134,7 +1181,8 @@ $error-color: error !default;
11341181
@include center-aligned($query: $query);
11351182
}
11361183

1137-
@if $new-height < $height {
1184+
// TODO(b/283457421): Account for dynamic height
1185+
@if _is-less-than($new-height, $height) {
11381186
@include dropdown-icon-size(
11391187
select-icon-theme.$dense-icon-size,
11401188
$query: $query
@@ -1175,7 +1223,8 @@ $error-color: error !default;
11751223
$query: $query
11761224
);
11771225

1178-
@if $new-height < $height {
1226+
// TODO(b/283457421): Account for dynamic height
1227+
@if _is-less-than($new-height, $height) {
11791228
@include select-icon-theme.size(
11801229
select-icon-theme.$dense-icon-size,
11811230
$query: $query
@@ -1218,12 +1267,20 @@ $error-color: error !default;
12181267
///
12191268
@mixin outlined-height(
12201269
$new-height,
1221-
$keyframe-suffix: select-outlined-#{$new-height},
1270+
$keyframe-suffix: null,
12221271
$query: feature-targeting.all()
12231272
) {
12241273
$feat-structure: feature-targeting.create-target($query, structure);
12251274
$positionY: get-outlined-label-position-y($new-height);
12261275

1276+
@if $keyframe-suffix == null {
1277+
$modifier: $new-height;
1278+
@if custom-properties.is-custom-prop($modifier) {
1279+
$modifier: custom-properties.get-fallback($modifier);
1280+
}
1281+
$keyframe-suffix: select-outlined-#{$modifier};
1282+
}
1283+
12271284
.mdc-select__anchor {
12281285
// Floating label position
12291286
@include notched-outline-mixins.floating-label-float-position-absolute(
@@ -1245,11 +1302,12 @@ $error-color: error !default;
12451302
}
12461303

12471304
@include feature-targeting.targets($feat-structure) {
1248-
height: $new-height;
1305+
@include theme.property(height, $new-height);
12491306
}
12501307
}
12511308

1252-
@if $new-height < $height {
1309+
// TODO(b/283457421): Account for dynamic height
1310+
@if _is-less-than($new-height, $height) {
12531311
@include dropdown-icon-size(
12541312
select-icon-theme.$dense-icon-size,
12551313
$query: $query
@@ -1280,7 +1338,8 @@ $error-color: error !default;
12801338
$feat-structure: feature-targeting.create-target($query, structure);
12811339

12821340
.mdc-select__anchor {
1283-
@if $new-height < $height {
1341+
// TODO(b/283457421): Account for dynamic height
1342+
@if _is-less-than($new-height, $height) {
12841343
@include dropdown-icon-size(
12851344
select-icon-theme.$dense-icon-size,
12861345
$query: $query
@@ -1301,11 +1360,12 @@ $error-color: error !default;
13011360
}
13021361

13031362
@include feature-targeting.targets($feat-structure) {
1304-
height: $new-height;
1363+
@include theme.property(height, $new-height);
13051364
}
13061365
}
13071366

1308-
@if $new-height < $height {
1367+
// TODO(b/283457421): Account for dynamic height
1368+
@if _is-less-than($new-height, $height) {
13091369
.mdc-deprecated-list-item__graphic {
13101370
width: select-icon-theme.$dense-icon-size;
13111371
height: select-icon-theme.$dense-icon-size;
@@ -1706,3 +1766,23 @@ $error-color: error !default;
17061766
}
17071767
}
17081768
}
1769+
1770+
///
1771+
/// Compare the two inputs even if they're custom-prop objects.
1772+
/// @access private
1773+
///
1774+
@function _is-less-than($subject, $object) {
1775+
$fallback-subject: if(
1776+
custom-properties.is-custom-prop($subject),
1777+
custom-properties.get-fallback($subject),
1778+
$subject
1779+
);
1780+
1781+
$fallback-object: if(
1782+
custom-properties.is-custom-prop($object),
1783+
custom-properties.get-fallback($object),
1784+
$object
1785+
);
1786+
1787+
@return $fallback-subject < $fallback-object;
1788+
}

0 commit comments

Comments
 (0)