Skip to content
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

USWDS - Windows High Contrast Mode Update #4610

Merged
merged 79 commits into from
Apr 5, 2022
Merged

Conversation

mahoneycm
Copy link
Contributor

@mahoneycm mahoneycm commented Mar 28, 2022

High contrast mode component improvements. Adds high contrast mode specific styling to components to prevent information loss.

Description

High contrast on Windows is an accessibility feature designed to increase text legibility and improve readability. The feature works by enabling the user to select theme colors for a scoped number of semantic elements. This scheme can then be applied to user interfaces and app content, reducing visual complexity while guaranteeing the user’s preferred contrast level.

In September 2020, Microsoft partnered with the CSS Working Group and the Chromium project, to set new web standards for developers to use to style their content for forced color modes like Windows high contrast. 1

While testing our USWDS components in Windows High Contrast mode, we found that there were important visual queues missing. This caused some components to be challenging to use for users who utilize this important feature. Pairing our place-icon() and add-color-icon() functions with system color defaults2 we are able to ensure maximum visibility of our components in Windows High Contrast mode or any mode that utilizes forced-color properties.

This PR affects the following:

  • System Tokens
  • place-icon() and add-color-icon() mixins
  • Accordion
  • Banner
  • Checkbox
  • Combobox
  • Date Picker & Date Range Picker
  • Footer
  • Header
  • Pagination
  • Radio Buttons
  • Range Slider
  • Search
  • Time Picker

Details of the changes and results will be broken up by component and listed in the comments below

Before you hit Submit, make sure you’ve done whichever of these applies to you:

  • Follow the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run npm test and make sure the tests for the files you have changed have passed.
  • Run your code through HTML_CodeSniffer and make sure it’s error free.
  • Title your pull request using this format: [Website] - [UI component]: Brief statement describing what this pull request solves.

Footnotes

  1. Styling for Windows high contrast with new standards for forced colors

  2. W3.org: System Colors

mahoneycm and others added 30 commits February 9, 2022 14:05
…uttons to allow checkmark to appear properly in high contrast mode
USWDS: Range Slider - Fixes high contrast visibility
USWDS: Radio Button & Checkbox - Windows High Contrast Support
USWDS - Pagination: Added stylings for Windows High Contrast mode
@@ -1697,3 +1697,23 @@ $system-color-shortcodes: (
"white-transparent-80": $color-white-transparent-80,
"white-transparent-90": $color-white-transparent-90,
);

$high-contrast-system-colors: (
Copy link
Contributor Author

@mahoneycm mahoneycm Mar 29, 2022

Choose a reason for hiding this comment

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

System Tokens

While it was possible to call the standard System Colors when declaring things like color or background-color, they were not able to be used in functions that required USWDS system tokens. This helps to implement these icons via place-icon() where you need to declare an icon object which requires color to be defined.

Trying to fix without setting system colors

When setting the image map, you can only set the color to USWDS color tokens. Trying to set it to a high contrast system color (ButtonText in this example), the add-color-icon function will fail

image

Results in:
image

To get around this, you can set the color to currentColor and changing the background color of the element to ButtonText but often times the style gets overridden by another setting.

Code
image
image

DevTools
image

Results in:
image

After setting system colors

After adding the new tokens, one can simply set the color to ButtonText to get the desired effect

Code
image
image

Results in
image

$contrast-bg
$margin: "auto",
$vertical-align: middle,
$contrast-bg: "default"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

place-icon() and add-color-icon() Defaults

Setting default values for these functions so users can simply set the icon object and direction while leaving the option to change the rest for optional specificity.


@media (forced-colors: active) {
forced-color-adjust: none;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accordion

Accordion was missing the expand and collapse icons which implied there was collapsed content hidden. By setting forced-color-adjust: none we can maintain original styling, which passes color contrast minimums.

Current High Contrast / High Contrast Fix: Dark Theme / High Contrast Fix: Light Theme
image

&::after {
background-color: ButtonText;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Banner

The banner was missing chevrons, which implies there is content hidden behind the link. It was also missing the close icon on mobile which allows users to close the pane.

The icons were already placed as masks using place-icon(), so the solution was simply setting the background color to an appropriate System Color

Current High Contrast / High Contrast FIx
image

&--tile {
background-color: ButtonText;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checkbox and Radio Buttons

Currently, the radio button and checkbox components are missing important visual queues for users implementing Windows High Contrast mode including the buttons/boxes themselves, when a selection has been made, and a visual queue of disabled form options.

Because most of the stylings are shared between Radio + Checkbox, it was easiest to fix together.

Radio Buttons

Currently:

Default

image

Tile

image

After Fix:

// Note: Bolder border around Radio button / checkbox indicates focus

Default:

image

Tile:

image

Checkbox

Currently

Default:

image

Tile:

image

After Fix

Default:

image

Tile:

image

The checkmark will not show in both cases due to the limitations of forced-colors mode being able to determine light or dark themes, to switch between the light and dark versions of the checkmark.

Our thinking was that the dark high contrast themes are more frequently used than the light themes, so the broader user base will get the most similar checkboxes, stylistically speaking, while the light users still maintain a functional componen

height: 1.5rem;
width: auto;
top: 0.5rem;
}
Copy link
Contributor Author

@mahoneycm mahoneycm Mar 29, 2022

Choose a reason for hiding this comment

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

Combo-box & Time Picker

This update keeps the background svg in standard views but places the icon mask in forced-colors is set to active.

This also fixes the same issue found in the Time Picker component

Currently

Standard
image

High Contrast mode
image

After Fix

image

@include add-color-icon($calendar);
mask-size: units(3) !important;
position: relative;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Date Range Picker

Currently:

Default:
image

HC Mode:
image

In it's current state, the calendar icon is missing, month & date arrows are missing, date selection and range are missing. This makes the component almost completely unusable for users utilizing High Contrast Mode

After Fix

image

_Note: the arrow to the left of March 2022 are hidden because it is out of the selection range _

</div>
<div class="${CALENDAR_CELL_CLASS} ${CALENDAR_CELL_CENTER_ITEMS_CLASS}">
<button
type="button"
class="${CALENDAR_PREVIOUS_MONTH_CLASS}"
aria-label="Navigate back one month"
${prevButtonsDisabled ? `disabled="disabled"` : ""}
>&nbsp;</button>
></button>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Date Picker JS

WHC changes the background color for all text. The &ngsp; causes a rectangle to appear and obstruct the icon masks:

image

image

After Fix

image

Copy link
Member

Choose a reason for hiding this comment

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

Wy was this &nbsp; here in the first place? Does removing it cause any kind of regression in any other browser?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've checked Chrome, Edge, and Firefox in both standard and High Contrast modes and have yet to find an error!

0.5,
"auto",
"default"
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Footer

Currently, social media icons and expand chevrons (mobile only) disappear in dark high contrast modes, causing the user to lose context and content.

This PR also fixes the disappearing chevrons in the big footer variant in mobile views.

Social Icons

Currently:
(Alternative color shows hover)

Default

image

High Contrast

image

After Fix:

Used forced-color-adjust: none to set the background color for the social link icons to lightgrey. This is easy to see in all high contrast modes and keeps things consistent between versions

image

Mobile Chevrons

Currently:

image

After Fix:

image


&::after {
position: absolute;
right: 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Header

In high contrast modes, the header would be missing chevrons, mobile open/close buttons, and the search button depending on theme color

(before and after)
image

Mobile
image

outline: 2px solid buttonText;
color: buttonText;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pagination

Before, the current page did not have depictive stylings so users could not easily see which page they are on, versus what is next or previous. This is mostly a problem in the unbounded variant where there are 4 page numbers grouped together.

Default:

image

Unbounded:

image

Current w/ high contrast:

image
image

Fix w/ high contrast:

image
image


@media (forced-colors: active) {
outline: 2px solid transparent;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Range

This adds an outline to the range slider handle (or "thumb") when high contrast mode is detected

Currently:

image

After Fix:

image


&::before {
@include at-media("mobile-lg") {
content: none;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Search

The search component was missing the button outline as well as the magnifying glass icon in high contrast modes.

Current High Contrast (left) / High Contrast Fix (right)
image

@mahoneycm mahoneycm marked this pull request as ready for review March 29, 2022 19:10
Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

Nice work!

Tested for regressions first across Chrome, Firefox, and Safari both on mobile and desktop. None found. High contrast styles look good on Edge.

There are slight issues with Firefox, but we expected that with limited support.

@thisisdano
Copy link
Member

This is a masterpiece of PR documentation, thank you.

@thisisdano thisisdano merged commit 1acc8d1 into develop Apr 5, 2022
@thisisdano thisisdano deleted the cm-high-contrast-a11y branch April 5, 2022 15:54
mejiaj pushed a commit that referenced this pull request Apr 8, 2022
USWDS - Windows High Contrast Mode Update
@thisisdano thisisdano mentioned this pull request Apr 11, 2022
lpsinger added a commit to nasa-gcn/gcn.nasa.gov that referenced this pull request Apr 26, 2022
uswds/uswds#4610, released in uswds 2.13.3, made some changes to
the implementation of theme colors that caused the nav bar to be
rendered incorrectly.
This was referenced Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants