Skip to content

Commit 5cf7d17

Browse files
crisbetommalerba
authored andcommitted
fix(a11y): improved accessibility in high contrast mode (#1941)
* fix: improved accessibility in high contrast mode a11y improvements to the following components in high contrast mode: * `button` - Adds an outline since only the text was visible. Also inverts the tint since it was hiding the text. * `card`, `dialog`, `menu`, `snack-bar`, `tooltip` - Adds an outline. * `select` - Adds an outline and prevents the ripple from hiding the option text. * `sidenav` - Fixes the backdrop not being opaque. * `slide-toggle` - Fixes component blending in completely with the background. Fixes #421. Fixes #1769. * Replace the "border" instances with "outline". * Move the overlay coloring to the button theme. * Move the overlay color back to the button base styles.
1 parent a695574 commit 5cf7d17

File tree

10 files changed

+74
-5
lines changed

10 files changed

+74
-5
lines changed

src/lib/button/button.scss

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// TODO(jelbourn): Figure out if anchor hover underline actually happens in any browser.
33

44
@import 'button-base';
5+
@import '../a11y/_a11y';
56

67
// TODO(kara): Replace attribute selectors with class selectors when possible
78
[md-button], [md-icon-button] {
@@ -79,6 +80,13 @@
7980
border-radius: inherit;
8081
pointer-events: none;
8182
opacity: 0;
83+
84+
@include md-high-contrast {
85+
// Note that IE will render this in the same way, no
86+
// matter whether the theme is light or dark. This helps
87+
// with the readability of focused buttons.
88+
background-color: rgba(white, 0.5);
89+
}
8290
}
8391

8492
// For round buttons, the ripple container should clip child ripples to a circle.
@@ -89,9 +97,9 @@
8997
z-index: 1;
9098
}
9199

92-
// Applies a clearer border for high-contrast mode (a11y)
93-
@media screen and (-ms-high-contrast: active) {
94-
.md-raised-button, .md-fab, .md-mini-fab {
95-
border: 1px solid #fff;
100+
// Add an outline to make it more visible in high contrast mode.
101+
@include md-high-contrast {
102+
[md-button], [md-raised-button], [md-icon-button], [md-fab], [md-mini-fab] {
103+
outline: solid 1px;
96104
}
97105
}

src/lib/card/card.scss

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import '../core/style/variables';
22
@import '../core/style/elevation';
3+
@import '../a11y/_a11y';
34

45

56
$md-card-default-padding: 24px !default;
@@ -15,6 +16,10 @@ md-card {
1516
padding: $md-card-default-padding;
1617
border-radius: $md-card-border-radius;
1718
font-family: $md-font-family;
19+
20+
@include md-high-contrast {
21+
outline: solid 1px;
22+
}
1823
}
1924

2025
.md-card-flat {

src/lib/core/a11y/_a11y.scss

+11
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@
1111
width: 1px;
1212
}
1313
}
14+
15+
/**
16+
* Applies styles for users in high contrast mode. Note that this only applies
17+
* to Microsoft browsers. Chrome can be included by checking for the `html[hc]`
18+
* attribute, however Chrome handles high contrast differently.
19+
*/
20+
@mixin md-high-contrast {
21+
@media screen and (-ms-high-contrast: active) {
22+
@content;
23+
}
24+
}

src/lib/dialog/dialog-container.scss

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import '../core/style/elevation';
2+
@import '../a11y/_a11y';
23

34

45
$md-dialog-padding: 24px !default;
@@ -16,4 +17,8 @@ md-dialog-container {
1617
// The dialog container should completely fill its parent overlay element.
1718
width: 100%;
1819
height: 100%;
20+
21+
@include md-high-contrast {
22+
outline: solid 1px;
23+
}
1924
}

src/lib/menu/menu.scss

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@import '../core/style/button-common';
55
@import '../core/style/layout-common';
66
@import '../core/style/menu-common';
7+
@import '../a11y/_a11y';
78

89
$md-menu-vertical-padding: 8px !default;
910

@@ -13,6 +14,10 @@ $md-menu-vertical-padding: 8px !default;
1314

1415
// max height must be 100% of the viewport height + one row height
1516
max-height: calc(100vh + 48px);
17+
18+
@include md-high-contrast {
19+
outline: solid 1px;
20+
}
1621
}
1722

1823
.md-menu-content {

src/lib/select/select.scss

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import '../core/style/menu-common';
22
@import '../core/style/form-common';
3+
@import '../a11y/_a11y';
34

45
$md-select-trigger-height: 30px !default;
56
$md-select-trigger-min-width: 112px !default;
@@ -96,6 +97,10 @@ md-select {
9697
padding-top: 0;
9798
padding-bottom: 0;
9899
max-height: $md-select-panel-max-height;
100+
101+
@include md-high-contrast {
102+
outline: solid 1px;
103+
}
99104
}
100105

101106
md-option {
@@ -116,4 +121,9 @@ md-option {
116121
left: 0;
117122
bottom: 0;
118123
right: 0;
119-
}
124+
125+
// In high contrast mode this completely covers the text.
126+
@include md-high-contrast {
127+
opacity: 0.5;
128+
}
129+
}

src/lib/sidenav/sidenav.scss

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import '../core/style/variables';
22
@import '../core/style/elevation';
33
@import '../core/style/layout-common';
4+
@import '../a11y/_a11y';
45

56

67
// Mixin to help with defining LTR/RTL 'transform: translate3d()' values.
@@ -83,6 +84,10 @@ md-sidenav-layout {
8384
&.md-sidenav-shown {
8485
visibility: visible;
8586
}
87+
88+
@include md-high-contrast {
89+
opacity: 0.5;
90+
}
8691
}
8792

8893
.md-sidenav-content {

src/lib/slide-toggle/slide-toggle.scss

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import '../core/style/variables';
22
@import '../core/ripple/ripple';
33
@import '../core/style/elevation';
4+
@import '../a11y/_a11y';
45

56

67
$md-slide-toggle-width: 36px !default;
@@ -116,6 +117,11 @@ md-slide-toggle {
116117
border-radius: 50%;
117118

118119
@include md-elevation(1);
120+
121+
@include md-high-contrast {
122+
background: #fff;
123+
border: solid 1px #000;
124+
}
119125
}
120126

121127
// Horizontal bar for the slide-toggle.
@@ -129,6 +135,10 @@ md-slide-toggle {
129135
height: $md-slide-toggle-bar-height;
130136

131137
border-radius: 8px;
138+
139+
@include md-high-contrast {
140+
background: #fff;
141+
}
132142
}
133143

134144
// The slide toggle shows a visually hidden input inside of the component, which is used

src/lib/snack-bar/snack-bar-container.scss

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import '../core/style/elevation';
2+
@import '../a11y/_a11y';
23

34
$md-snack-bar-padding: 14px 24px !default;
45
$md-snack-bar-height: 20px !default;
@@ -19,4 +20,8 @@ $md-snack-bar-max-width: 568px !default;
1920
padding: $md-snack-bar-padding;
2021
// Initial transformation is applied to start snack bar out of view.
2122
transform: translateY(100%);
23+
24+
@include md-high-contrast {
25+
border: solid 1px;
26+
}
2227
}

src/lib/tooltip/tooltip.scss

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import '../core/style/variables';
2+
@import '../a11y/_a11y';
23

34

45
$md-tooltip-height: 22px;
@@ -18,4 +19,8 @@ $md-tooltip-padding: 8px;
1819
margin: $md-tooltip-margin;
1920
height: $md-tooltip-height;
2021
line-height: $md-tooltip-height;
22+
23+
@include md-high-contrast {
24+
outline: solid 1px;
25+
}
2126
}

0 commit comments

Comments
 (0)