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

Improve focus state for radio and checkbox controls in forced colors mode (for example, Windows High Contrast Mode) #2264

Merged
merged 2 commits into from
Jul 2, 2021

Conversation

36degrees
Copy link
Contributor

@36degrees 36degrees commented Jul 1, 2021

The focus state for radios and checkboxes is currently not very visible in high contrast mode or when colours are overridden in Firefox – the only visible change is that the outer border of the radio or checkbox control thickens from 2px to 4px. This is the same as the part of the focus state change that meets contrast, but omits the yellow ‘ring’ created by the box shadow.

Add an additional transparent outline to the control. In forced colors mode, transparent borders become solid (matching the text / foreground color) and so we get an additional outline around the focused control making it clearly visible.

When explicitly in forced-color mode, we can enhance the outline further by using the Highlight system color, which matches the color used by the focus state of native controls – at least in in Edge / Chrome / Opera which are the only other browsers to support forced color mode.

Fixes #2258

Browser Before After
Internet Explorer 11 ie-before ie-after
Chrome chrome-before chrome-after
Edge edge-before edge-after
Firefox (High Contrast Mode) ff-hcm-before ff-hcm-after
Firefox (Custom Colours) ff-custom-before ff-custom-after

A native focused text input in Edge in High Contrast Mode, for comparison:

Screenshot 2021-07-01 at 17 45 05

The focus state for radios and checkboxes is currently not very visible in high contrast mode or when colours are overridden in Firefox – the only visible change is that the outer border of the radio or checkbox control thickens from 2px to 4px. This is the same as the part of the focus state change that meets contrast, but omits the yellow ‘ring’ created by the box shadow.

Add an additional transparent outline to the control. In forced colors mode, transparent borders become solid (matching the text / foreground color) and so we get an additional outline around the focused control making it clearly visible.

When explicitly in forced-color mode, we can enhance the outline further by using the Highlight system color, which matches the color used by the focus state of native controls – at least in in Edge / Chrome / Opera which are the only other browsers to support forced color mode.
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2264 July 1, 2021 16:28 Inactive
@36degrees 36degrees marked this pull request as ready for review July 2, 2021 08:29
Copy link
Contributor

@vanitabarrett vanitabarrett left a comment

Choose a reason for hiding this comment

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

Seems like a sensible change. Tested in Windows and Firefox high contrast modes and works well.

@vanitabarrett
Copy link
Contributor

@36degrees Can we add a Changelog entry for this?

@36degrees 36degrees changed the title Improve focus for controls in forced color mode Improve focus state for radio and checkbox controls in forced color mode (for example Windows High Contrast Mode) Jul 2, 2021
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2264 July 2, 2021 11:01 Inactive
@36degrees 36degrees merged commit ecd839c into main Jul 2, 2021
@36degrees 36degrees deleted the radios-checkboxes-hcm-focus branch July 2, 2021 13:43
@EoinShaughnessy
Copy link
Contributor

EoinShaughnessy commented Aug 17, 2021

Is it 'forced color mode' or 'forced colors mode'? I thought it might be the latter because 'forced colors mode' is the one I've seen more of online. For example, in Chrome and Mozilla. If it is the latter, then we probably need to tweak the title of both this ticket and similar tickets in any upcoming fix release...

@36degrees
Copy link
Contributor Author

Good catch!

The Windows blog post (https://blogs.windows.com/msedgedev/2020/09/17/styling-for-windows-high-contrast-with-new-standards-for-forced-colors/) uses both terms interchangeably, but 'forced color mode' more often – which I think influenced my usage of the term originally.

However, I think the canonical resource to refer to for this is the CSS Color Adjustment Module Level 1 specification, which includes 'forced colors mode' as a defined term.

@EoinShaughnessy EoinShaughnessy changed the title Improve focus state for radio and checkbox controls in forced color mode (for example Windows High Contrast Mode) Improve focus state for radio and checkbox controls in forced colors mode (for example Windows High Contrast Mode) Aug 17, 2021
@EoinShaughnessy
Copy link
Contributor

Thanks, @36degrees. I've updated this PR's title, along with those for #2265, #2273 and #2277. I'll also update the Changelog entries when I raise a PR for the notes.

lfdebrux added a commit that referenced this pull request Aug 19, 2021
Adds IE11 supportto the previous Windows High Contrast Mode fixes in PR
#2264.

Internet Explorer 11 doesn't support the `forced-colors` media feature
or the `forced-color-adjust` property, but it has equivalents in
`-ms-high-contrast` and `-ms-high-contrast-adjust`.
We can use those CSS features to extend fixes to high contrast mode that
previously only worked on more modern browsers.

Adds a tweak to changes in commit 7dcba7d, so that the highlight works
in Internet Explorer 11 as well.
@EoinShaughnessy EoinShaughnessy changed the title Improve focus state for radio and checkbox controls in forced colors mode (for example Windows High Contrast Mode) Improve focus state for radio and checkbox controls in forced colors mode (for example, Windows High Contrast Mode) Aug 31, 2021
@vanitabarrett vanitabarrett mentioned this pull request Sep 7, 2021
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.

Radios and checkboxes do not follow native colours in Windows High Contrast
4 participants