Skip to content

Commit 25ce8e7

Browse files
committed
fix(material/select): add selected indication in high contrast mode (#25237)
Currently we don't indicate which `mat-option` is selected in single-selection mode to high contrast users. These changes add a small indicator similar to the one in `mat-selection-list`. (cherry picked from commit 5c8c7e8)
1 parent 9cd5a6a commit 25ce8e7

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

src/material-experimental/mdc-core/option/option.scss

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@use '@angular/cdk';
22
@use '@angular/material' as mat;
3+
@use '@angular/cdk';
34
@use '@material/list/evolution-mixins' as mdc-list-mixins;
45
@use '@material/list/evolution-variables' as mdc-list-variables;
56
@use 'sass:map';
@@ -26,15 +27,6 @@
2627
$height-config: map.get(mdc-list-variables.$one-line-item-density-config, height);
2728
min-height: map.get($height-config, default);
2829

29-
// Workaround for https://goo.gl/pFmjJD in IE 11. Adds a pseudo
30-
// element that will stretch the option to the correct height. See:
31-
// https://connect.microsoft.com/IE/feedback/details/802625
32-
&::after {
33-
display: inline-block;
34-
min-height: inherit;
35-
content: '';
36-
}
37-
3830
&.mdc-list-item--disabled {
3931
// This is the same as `mdc-list-mixins.list-disabled-opacity` which
4032
// we can't use directly, because it comes with some selectors.
@@ -89,6 +81,29 @@
8981
text-decoration: inherit;
9082
text-transform: inherit;
9183
}
84+
85+
@include cdk.high-contrast(active, off) {
86+
// In single selection mode, the selected option is indicated by changing its
87+
// background color, but that doesn't work in high contrast mode. We add an
88+
// alternate indication by rendering out a circle.
89+
&.mdc-list-item--selected:not(.mat-mdc-option-multiple)::after {
90+
$size: 10px;
91+
content: '';
92+
position: absolute;
93+
top: 50%;
94+
right: mdc-list-variables.$side-padding;
95+
transform: translateY(-50%);
96+
width: $size;
97+
height: 0;
98+
border-bottom: solid $size;
99+
border-radius: $size;
100+
}
101+
102+
[dir='rtl'] &.mdc-list-item--selected:not(.mat-mdc-option-multiple)::after {
103+
right: auto;
104+
left: mdc-list-variables.$side-padding;
105+
}
106+
}
92107
}
93108

94109
.mat-mdc-option-active {

src/material/core/option/option.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@
5353
&[aria-disabled='true'] {
5454
opacity: 0.5;
5555
}
56+
57+
// In single selection mode, the selected option is indicated by changing its
58+
// background color, but that doesn't work in high contrast mode. We add an
59+
// alternate indication by rendering out a circle.
60+
&.mat-selected:not(.mat-option-multiple)::after {
61+
$size: 10px;
62+
content: '';
63+
position: absolute;
64+
top: 50%;
65+
right: menu-common.$side-padding;
66+
transform: translateY(-50%);
67+
width: $size;
68+
height: 0;
69+
border-bottom: solid $size;
70+
border-radius: $size;
71+
}
72+
73+
[dir='rtl'] &.mat-selected:not(.mat-option-multiple)::after {
74+
right: auto;
75+
left: menu-common.$side-padding;
76+
}
5677
}
5778
}
5879

0 commit comments

Comments
 (0)