Skip to content

Commit 5ed3a6b

Browse files
committed
refactor(material/core): simplify structural styles (#29269)
Simplifies the structural styles of `mat-option` and `mat-optgroup` to make them easier to maintain. (cherry picked from commit 607da66)
1 parent bad8f6a commit 5ed3a6b

File tree

2 files changed

+29
-41
lines changed

2 files changed

+29
-41
lines changed

src/material/core/option/optgroup.scss

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
@use 'sass:map';
2-
@use '@material/list/evolution-mixins' as mdc-list-mixins;
3-
@use '@material/list/evolution-variables' as mdc-list-variables;
41
@use '../tokens/m2/mat/optgroup' as tokens-mat-optgroup;
52
@use '../tokens/token-utils';
6-
@use '../mdc-helpers/mdc-helpers';
73

84
.mat-mdc-optgroup {
95
// These tokens are set on the root option group to make them easier to override.
@@ -19,20 +15,17 @@
1915
}
2016

2117
.mat-mdc-optgroup-label {
22-
@include mdc-list-mixins.item-base;
23-
@include mdc-list-mixins.item-spacing(
24-
mdc-list-variables.$side-padding, $query: mdc-helpers.$mdc-base-styles-query);
25-
26-
// Set the `min-height` here ourselves, instead of going through
27-
// the `mdc-list-one-line-item-density` mixin, because it sets a `height`
28-
// which doesn't work well with multi-line options.
29-
$height-config: map.get(mdc-list-variables.$one-line-item-density-config, height);
30-
min-height: map.get($height-config, default);
18+
display: flex;
19+
position: relative;
20+
align-items: center;
21+
justify-content: flex-start;
22+
overflow: hidden;
23+
min-height: 48px;
24+
padding: 0 16px;
25+
outline: none;
3126

3227
&.mdc-list-item--disabled {
33-
// This is the same as `mdc-list-mixins.list-disabled-opacity` which
34-
// we can't use directly, because it comes with some selectors.
35-
opacity: mdc-list-variables.$content-disabled-opacity;
28+
opacity: 0.38;
3629
}
3730

3831
// Needs to be overwritten explicitly, because the style can

src/material/core/option/option.scss

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
@use 'sass:map';
21
@use '@angular/cdk';
3-
@use '@material/list/evolution-mixins' as mdc-list-mixins;
4-
@use '@material/list/evolution-variables' as mdc-list-variables;
5-
@use '@material/typography/typography' as mdc-typography;
62

73
@use '../tokens/m2/mat/option' as tokens-mat-option;
84
@use '../tokens/m2/mdc/list' as tokens-mdc-list;
95
@use '../tokens/token-utils';
10-
@use '../mdc-helpers/mdc-helpers';
116
@use '../style/vendor-prefixes';
127
@use '../style/layout-common';
138

9+
$_side-padding: 16px;
1410

1511
.mat-mdc-option {
16-
@include mdc-list-mixins.item-base;
17-
@include mdc-list-mixins.item-spacing(
18-
mdc-list-variables.$side-padding, $query: mdc-helpers.$mdc-base-styles-query);
1912
@include vendor-prefixes.user-select(none);
20-
@include mdc-typography.smooth-font();
13+
@include vendor-prefixes.smooth-font();
14+
display: flex;
15+
position: relative;
16+
align-items: center;
17+
justify-content: flex-start;
18+
overflow: hidden;
19+
min-height: 48px;
20+
padding: 0 16px;
2121
cursor: pointer;
2222
-webkit-tap-highlight-color: transparent;
2323

@@ -38,6 +38,7 @@
3838
&:focus.mdc-list-item,
3939
&.mat-mdc-option-active.mdc-list-item {
4040
@include token-utils.create-token-slot(background-color, focus-state-layer-color);
41+
outline: 0;
4142
}
4243

4344
&.mdc-list-item--selected:not(.mdc-list-item--disabled) {
@@ -65,12 +66,6 @@
6566
background: transparent;
6667
}
6768

68-
// Set the `min-height` here ourselves, instead of going through
69-
// the `mdc-list-one-line-item-density` mixin, because it sets a `height`
70-
// which doesn't work well with multi-line options.
71-
$height-config: map.get(mdc-list-variables.$one-line-item-density-config, height);
72-
min-height: map.get($height-config, default);
73-
7469
&.mdc-list-item--disabled {
7570
// This is the same as `mdc-list-mixins.list-disabled-opacity` which
7671
// we can't use directly, because it comes with some selectors.
@@ -84,7 +79,7 @@
8479
// MatOption uses a child `<div>` element for its focus state to align with how ListItem does
8580
// its focus state.
8681
.mat-mdc-option-pseudo-checkbox, .mdc-list-item__primary-text, > mat-icon {
87-
opacity: mdc-list-variables.$content-disabled-opacity;
82+
opacity: 0.38;
8883
}
8984

9085
// Prevent clicking on disabled options with mouse. Support focusing on disabled option using
@@ -96,31 +91,31 @@
9691
// Note that we bump the padding here, rather than padding inside the
9792
// group so that ripples still reach to the edges of the panel.
9893
.mat-mdc-optgroup &:not(.mat-mdc-option-multiple) {
99-
padding-left: mdc-list-variables.$side-padding * 2;
94+
padding-left: $_side-padding * 2;
10095

10196
[dir='rtl'] & {
102-
padding-left: mdc-list-variables.$side-padding;
103-
padding-right: mdc-list-variables.$side-padding * 2;
97+
padding-left: $_side-padding;
98+
padding-right: $_side-padding * 2;
10499
}
105100
}
106101

107102
.mat-icon,
108103
.mat-pseudo-checkbox-full {
109-
margin-right: mdc-list-variables.$side-padding;
104+
margin-right: $_side-padding;
110105
flex-shrink: 0;
111106

112107
[dir='rtl'] & {
113108
margin-right: 0;
114-
margin-left: mdc-list-variables.$side-padding;
109+
margin-left: $_side-padding;
115110
}
116111
}
117112

118113
.mat-pseudo-checkbox-minimal {
119-
margin-left: mdc-list-variables.$side-padding;
114+
margin-left: $_side-padding;
120115
flex-shrink: 0;
121116

122117
[dir='rtl'] & {
123-
margin-right: mdc-list-variables.$side-padding;
118+
margin-right: $_side-padding;
124119
margin-left: 0;
125120
}
126121
}
@@ -169,7 +164,7 @@
169164
content: '';
170165
position: absolute;
171166
top: 50%;
172-
right: mdc-list-variables.$side-padding;
167+
right: $_side-padding;
173168
transform: translateY(-50%);
174169
width: $size;
175170
height: 0;
@@ -179,7 +174,7 @@
179174

180175
[dir='rtl'] &.mdc-list-item--selected:not(.mat-mdc-option-multiple)::after {
181176
right: auto;
182-
left: mdc-list-variables.$side-padding;
177+
left: $_side-padding;
183178
}
184179
}
185180
}

0 commit comments

Comments
 (0)