Skip to content

Commit

Permalink
fix(a11y): improved accessibility in high contrast mode (#1941)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
crisbeto authored and mmalerba committed Dec 5, 2016
1 parent a695574 commit 5cf7d17
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/lib/button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// TODO(jelbourn): Figure out if anchor hover underline actually happens in any browser.

@import 'button-base';
@import '../a11y/_a11y';

// TODO(kara): Replace attribute selectors with class selectors when possible
[md-button], [md-icon-button] {
Expand Down Expand Up @@ -79,6 +80,13 @@
border-radius: inherit;
pointer-events: none;
opacity: 0;

@include md-high-contrast {
// Note that IE will render this in the same way, no
// matter whether the theme is light or dark. This helps
// with the readability of focused buttons.
background-color: rgba(white, 0.5);
}
}

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

// Applies a clearer border for high-contrast mode (a11y)
@media screen and (-ms-high-contrast: active) {
.md-raised-button, .md-fab, .md-mini-fab {
border: 1px solid #fff;
// Add an outline to make it more visible in high contrast mode.
@include md-high-contrast {
[md-button], [md-raised-button], [md-icon-button], [md-fab], [md-mini-fab] {
outline: solid 1px;
}
}
5 changes: 5 additions & 0 deletions src/lib/card/card.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import '../core/style/variables';
@import '../core/style/elevation';
@import '../a11y/_a11y';


$md-card-default-padding: 24px !default;
Expand All @@ -15,6 +16,10 @@ md-card {
padding: $md-card-default-padding;
border-radius: $md-card-border-radius;
font-family: $md-font-family;

@include md-high-contrast {
outline: solid 1px;
}
}

.md-card-flat {
Expand Down
11 changes: 11 additions & 0 deletions src/lib/core/a11y/_a11y.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@
width: 1px;
}
}

/**
* Applies styles for users in high contrast mode. Note that this only applies
* to Microsoft browsers. Chrome can be included by checking for the `html[hc]`
* attribute, however Chrome handles high contrast differently.
*/
@mixin md-high-contrast {
@media screen and (-ms-high-contrast: active) {
@content;
}
}
5 changes: 5 additions & 0 deletions src/lib/dialog/dialog-container.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../core/style/elevation';
@import '../a11y/_a11y';


$md-dialog-padding: 24px !default;
Expand All @@ -16,4 +17,8 @@ md-dialog-container {
// The dialog container should completely fill its parent overlay element.
width: 100%;
height: 100%;

@include md-high-contrast {
outline: solid 1px;
}
}
5 changes: 5 additions & 0 deletions src/lib/menu/menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@import '../core/style/button-common';
@import '../core/style/layout-common';
@import '../core/style/menu-common';
@import '../a11y/_a11y';

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

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

// max height must be 100% of the viewport height + one row height
max-height: calc(100vh + 48px);

@include md-high-contrast {
outline: solid 1px;
}
}

.md-menu-content {
Expand Down
12 changes: 11 additions & 1 deletion src/lib/select/select.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import '../core/style/menu-common';
@import '../core/style/form-common';
@import '../a11y/_a11y';

$md-select-trigger-height: 30px !default;
$md-select-trigger-min-width: 112px !default;
Expand Down Expand Up @@ -96,6 +97,10 @@ md-select {
padding-top: 0;
padding-bottom: 0;
max-height: $md-select-panel-max-height;

@include md-high-contrast {
outline: solid 1px;
}
}

md-option {
Expand All @@ -116,4 +121,9 @@ md-option {
left: 0;
bottom: 0;
right: 0;
}

// In high contrast mode this completely covers the text.
@include md-high-contrast {
opacity: 0.5;
}
}
5 changes: 5 additions & 0 deletions src/lib/sidenav/sidenav.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import '../core/style/variables';
@import '../core/style/elevation';
@import '../core/style/layout-common';
@import '../a11y/_a11y';


// Mixin to help with defining LTR/RTL 'transform: translate3d()' values.
Expand Down Expand Up @@ -83,6 +84,10 @@ md-sidenav-layout {
&.md-sidenav-shown {
visibility: visible;
}

@include md-high-contrast {
opacity: 0.5;
}
}

.md-sidenav-content {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/slide-toggle/slide-toggle.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import '../core/style/variables';
@import '../core/ripple/ripple';
@import '../core/style/elevation';
@import '../a11y/_a11y';


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

@include md-elevation(1);

@include md-high-contrast {
background: #fff;
border: solid 1px #000;
}
}

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

border-radius: 8px;

@include md-high-contrast {
background: #fff;
}
}

// The slide toggle shows a visually hidden input inside of the component, which is used
Expand Down
5 changes: 5 additions & 0 deletions src/lib/snack-bar/snack-bar-container.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../core/style/elevation';
@import '../a11y/_a11y';

$md-snack-bar-padding: 14px 24px !default;
$md-snack-bar-height: 20px !default;
Expand All @@ -19,4 +20,8 @@ $md-snack-bar-max-width: 568px !default;
padding: $md-snack-bar-padding;
// Initial transformation is applied to start snack bar out of view.
transform: translateY(100%);

@include md-high-contrast {
border: solid 1px;
}
}
5 changes: 5 additions & 0 deletions src/lib/tooltip/tooltip.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../core/style/variables';
@import '../a11y/_a11y';


$md-tooltip-height: 22px;
Expand All @@ -18,4 +19,8 @@ $md-tooltip-padding: 8px;
margin: $md-tooltip-margin;
height: $md-tooltip-height;
line-height: $md-tooltip-height;

@include md-high-contrast {
outline: solid 1px;
}
}

0 comments on commit 5cf7d17

Please sign in to comment.