Skip to content

fix: improved accessibility in high contrast mode #1941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be an issue with dark themes (where the text is white)?

(same for other components where you use a white background)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably would, but I only went for the dark modes in this PR since supporting all modes would add more bloat.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we make these styles part of the theme, they can simply use the theme's background and foreground palettes to draw an appropriate color.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would look something like

// in _button-theme.scss
@include md-high-contrast {
  background-color: if($theme.is-dark, white, black);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, although I had to flip the conditions since the colors are inverted. Might have to re-test this after we have dark themes implemented.

}
}

// 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 @@ -81,6 +82,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 @@ -101,4 +106,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;
}
}