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

A11Y: Improvements to <DToggleSwitch/> component #23514

Merged
merged 6 commits into from Sep 11, 2023

Conversation

keegangeorge
Copy link
Member

@keegangeorge keegangeorge commented Sep 11, 2023

This PR makes various improvements to the <DToggleSwitch/> component:

  • Modernizes component by converting to a single .gjs file.
  • Using gap property to control spacing between the toggle switch and its label. This is better than a margin-right because the gap will only be present if the label is also present, and therefore prevents a trailing margin for switches without labels
  • Improves accessibility by allowing the ability to focus over a toggle switch and press Enter to toggle the switch on and off
  • Improves the focus state so that there is an offset on the outline, making it clear the element is focused while the switch is toggled on (due to the clash in tertiary colors)
  • If a user prefers-reduced-motion, slider of the toggle will switch without a transition

Preview:

Screen.Recording.2023-09-11.at.10.47.13.mov

Using `gap` instead of `margin-right` allows there to only be a spacing when there is a label present, otherwise when the toggle is used without a label, there shouldn't be any spacing on the right.
The tertiary color on the checked toggle can be hard to see, so the added offset will make it clear that the element is focused.
Since the toggle switch element is a `<button>` not an `<input>`, we should be using `aria-pressed` instead of `aria-checked`
`aria-checked` can be used instead of `aria-pressed` due to `role="switch"` attribute on the button which treats the `<button>` like a checkbox
@keegangeorge keegangeorge merged commit 4238c57 into main Sep 11, 2023
17 checks passed
@keegangeorge keegangeorge deleted the a11y-d-toggle-switch branch September 11, 2023 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants