Skip to content

Commit 5c8c7e8

Browse files
authored
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`.
1 parent 089eb6f commit 5c8c7e8

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,4 +1,5 @@
11
@use '@angular/material' as mat;
2+
@use '@angular/cdk';
23
@use '@material/list/evolution-mixins' as mdc-list-mixins;
34
@use '@material/list/evolution-variables' as mdc-list-variables;
45
@use 'sass:map';
@@ -24,15 +25,6 @@
2425
$height-config: map.get(mdc-list-variables.$one-line-item-density-config, height);
2526
min-height: map.get($height-config, default);
2627

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

92107
// For options, render the focus indicator when the class .mat-mdc-option-active is present.

src/material/core/option/option.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@
4343
&[aria-disabled='true'] {
4444
opacity: 0.5;
4545
}
46+
47+
// In single selection mode, the selected option is indicated by changing its
48+
// background color, but that doesn't work in high contrast mode. We add an
49+
// alternate indication by rendering out a circle.
50+
&.mat-selected:not(.mat-option-multiple)::after {
51+
$size: 10px;
52+
content: '';
53+
position: absolute;
54+
top: 50%;
55+
right: menu-common.$side-padding;
56+
transform: translateY(-50%);
57+
width: $size;
58+
height: 0;
59+
border-bottom: solid $size;
60+
border-radius: $size;
61+
}
62+
63+
[dir='rtl'] &.mat-selected:not(.mat-option-multiple)::after {
64+
right: auto;
65+
left: menu-common.$side-padding;
66+
}
4667
}
4768
}
4869

0 commit comments

Comments
 (0)