Skip to content

Commit 440d2f5

Browse files
committed
fix(material/select): ensure arrow is centered on all densities
On lower densities some form field appearances hide the label which caused the arrow to be misaligned. These changes switch the arrow to absolute position which should be more robust. Fixes #26757.
1 parent 4888ffd commit 440d2f5

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/material/select/select.scss

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@ $scale: 0.75 !default;
2222
display: inline-block;
2323
width: 100%;
2424
outline: none;
25+
26+
// Outside a form field we want `relative` to contain any absolute child elements.
27+
position: relative;
28+
29+
// Inside a form field we want `static` so that absolute child
30+
// elements can be positioned relative to the form field.
31+
.mat-mdc-form-field & {
32+
position: static;
33+
}
2534
}
2635

2736
.mat-mdc-select-trigger {
2837
display: inline-flex;
2938
align-items: center;
3039
cursor: pointer;
31-
position: relative;
3240
box-sizing: border-box;
3341
width: 100%;
3442

@@ -39,10 +47,17 @@ $scale: 0.75 !default;
3947
}
4048

4149
.mat-mdc-select-value {
50+
$horizontal-padding: $mat-select-arrow-size * 2;
4251
width: 100%;
4352
overflow: hidden;
4453
text-overflow: ellipsis;
4554
white-space: nowrap;
55+
padding-right: $horizontal-padding;
56+
57+
[dir='rtl'] & {
58+
padding-left: $horizontal-padding;
59+
padding-right: 0;
60+
}
4661
}
4762

4863
.mat-mdc-select-value-text {
@@ -52,18 +67,14 @@ $scale: 0.75 !default;
5267
}
5368

5469
.mat-mdc-select-arrow-wrapper {
55-
height: 24px;
56-
flex-shrink: 0;
57-
display: inline-flex;
58-
align-items: center;
59-
60-
// When used in a fill appearance with a label, form-field the arrow should be shifted up 8px.
61-
.mat-form-field-appearance-fill & {
62-
transform: translateY(-8px);
63-
}
64-
65-
.mat-form-field-appearance-fill .mdc-text-field--no-label & {
66-
transform: none;
70+
position: absolute;
71+
top: 50%;
72+
right: 0;
73+
transform: translateY(-50%);
74+
75+
[dir='rtl'] & {
76+
right: auto;
77+
left: 0;
6778
}
6879
}
6980

@@ -73,11 +84,12 @@ $scale: 0.75 !default;
7384
position: relative;
7485

7586
svg {
76-
fill: currentColor;
87+
// Needs to be absolute, because it's actually larger than the container.
7788
position: absolute;
7889
top: 50%;
7990
left: 50%;
8091
transform: translate(-50%, -50%);
92+
fill: currentColor;
8193

8294
@include cdk.high-contrast(active, off) {
8395
// On Chromium browsers the `currentColor` blends in with the

0 commit comments

Comments
 (0)