Skip to content

Commit 2686bfe

Browse files
authored
fix(material/list): visually indicate active links in HCM (#25679)
For anchor tags inside of a list, draw a circle in HCM mode to indicate the active link item. This fixes an a11y issue where active list-items had no visual indication of being active in HCM.
1 parent 9f0071d commit 2686bfe

File tree

5 files changed

+56
-27
lines changed

5 files changed

+56
-27
lines changed

src/dev-app/list/list-demo.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ export class ListDemo {
5353
];
5454

5555
links: {name: string; href: string}[] = [
56-
{name: 'Inbox', href: '/mdc-list#inbox'},
57-
{name: 'Outbox', href: '/mdc-list#outbox'},
58-
{name: 'Spam', href: '/mdc-list#spam'},
59-
{name: 'Trash', href: '/mdc-list#trash'},
56+
{name: 'Inbox', href: '/list#inbox'},
57+
{name: 'Outbox', href: '/list#outbox'},
58+
{name: 'Spam', href: '/list#spam'},
59+
{name: 'Trash', href: '/list#trash'},
6060
];
6161

6262
thirdLine = false;

src/material/list/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,19 @@ ng_module(
3636
],
3737
)
3838

39+
sass_library(
40+
name = "hcm_indicator_scss_lib",
41+
srcs = ["_list-item-hcm-indicator.scss"],
42+
deps = [
43+
"//:mdc_sass_lib",
44+
],
45+
)
46+
3947
sass_library(
4048
name = "list_scss_lib",
4149
srcs = glob(["**/_*.scss"]),
4250
deps = [
51+
":hcm_indicator_scss_lib",
4352
"//:mdc_sass_lib",
4453
"//src/material/checkbox:checkbox_scss_lib",
4554
"//src/material/core:core_scss_lib",
@@ -50,6 +59,7 @@ sass_binary(
5059
name = "list_scss",
5160
src = "list.scss",
5261
deps = [
62+
":hcm_indicator_scss_lib",
5363
"//:mdc_sass_lib",
5464
"//src/material/core:core_scss_lib",
5565
],
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@use '@angular/cdk';
2+
@use '@material/list/evolution-variables' as mdc-list-variables;
3+
4+
// Renders a circle indicator when Windows Hich Constrast mode (HCM) is enabled. In some
5+
// situations, such as a selected option, the list item communicates the selected state by changing
6+
// its background color. Since that doesn't work in HCM, this mixin provides an alternative by
7+
// rendering a circle.
8+
@mixin private-high-contrast-list-item-indicator() {
9+
@include cdk.high-contrast(active, off) {
10+
&::after {
11+
$size: 10px;
12+
content: '';
13+
position: absolute;
14+
top: 50%;
15+
right: mdc-list-variables.$side-padding;
16+
transform: translateY(-50%);
17+
width: $size;
18+
height: 0;
19+
border-bottom: solid $size;
20+
border-radius: $size;
21+
}
22+
23+
[dir='rtl'] {
24+
&::after {
25+
right: auto;
26+
left: mdc-list-variables.$side-padding;
27+
}
28+
}
29+
}
30+
}

src/material/list/list-option.scss

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
@use 'sass:map';
2-
@use '@angular/cdk';
32
@use '@material/checkbox/checkbox' as mdc-checkbox;
4-
@use '@material/list/evolution-variables' as mdc-list-variables;
53
@use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
64

75
@use '../core/mdc-helpers/mdc-helpers';
86
@use '../checkbox/checkbox-private';
97
@use './list-option-trailing-avatar-compat';
8+
@use './list-item-hcm-indicator';
109

1110
// For compatibility with the non-MDC list, we support avatars that are shown at the end
1211
// of the list option. We create a class similar to MDC's `--trailing-icon` one.
@@ -53,25 +52,8 @@
5352
}
5453
}
5554

56-
@include cdk.high-contrast(active, off) {
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-mdc-list-option.mdc-list-item--selected::after {
61-
$size: 10px;
62-
content: '';
63-
position: absolute;
64-
top: 50%;
65-
right: mdc-list-variables.$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-mdc-list-option.mdc-list-item--selected::after {
74-
right: auto;
75-
left: mdc-list-variables.$side-padding;
76-
}
55+
.mat-mdc-list-option.mdc-list-item--selected {
56+
// Improve accessibility for Window High Contrast Mode (HCM) by adding an idicator on the selected
57+
// option.
58+
@include list-item-hcm-indicator.private-high-contrast-list-item-indicator();
7759
}

src/material/list/list.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
@use '@material/list/evolution-mixins' as mdc-list;
22
@use '../core/style/layout-common';
33
@use '../core/mdc-helpers/mdc-helpers';
4+
@use './list-item-hcm-indicator';
45

56
@include mdc-helpers.disable-mdc-fallback-declarations {
67
@include mdc-list.without-ripple($query: mdc-helpers.$mdc-base-styles-query);
78
}
89

10+
a.mdc-list-item--activated {
11+
// Improve accessibility for Window High Contrast Mode (HCM) by adding an idicator on active
12+
// links.
13+
@include list-item-hcm-indicator.private-high-contrast-list-item-indicator();
14+
}
15+
916
// MDC expects the list element to be a `<ul>`, since we use `<mat-list>` instead we need to
1017
// explicitly set `display: block`
1118
.mat-mdc-list-base {

0 commit comments

Comments
 (0)