Skip to content

Commit 07feece

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 e892e62 commit 07feece

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';
@@ -25,15 +26,6 @@
2526
$height-config: map.get(mdc-list-variables.$one-line-item-density-config, height);
2627
min-height: map.get($height-config, default);
2728

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

93108
// 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)