question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: use button for toggles instead of checkbox

See original GitHub issue

Currently, the Toggle and ToggleSmall components use <input type="checkbox"> under the hood. I’d like to propose switching this implementation to <button role="switch"> for the following two reasons:

Accessibility

The WAI-ARIA Authoring Practices 1.1 describe the switch role as “A type of checkbox that represents on/off values, as opposed to checked/unchecked values”. Compared to a checkbox, a button with role="switch" cannot have a mixed state, which a toggle should never have either. According to the W3C, assistive technologies will “present the widget in a fashion consistent with its on-screen appearance”.

Related guidance on MDN: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Switch_role

Preventing bugs

A checkbox cannot be toggled by pressing the <kbd>enter</kbd> key by default, which led to a PR last year that added this functionality by using the keyup event. When using a toggle as the first focused element in a modal or overflow menu (by using props.selectorPrimaryFocus), it will automatically be triggered if the modal or overflow menu is opened by pressing the <kbd>enter</kbd> key instead of space. This is not expected by the user and can lead to confusion and unintended changes in a user’s settings.

Demo: https://bc02h.csb.app/

The issue is only noticeable with the modal when the <kbd>enter</kbd> key is pressed for a bit longer and released as soon as the modal is visible. This therefore affects mostly users with motion impairment. The effect on an overflow menu is instant and affects all users.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
janhasselcommented, Jun 2, 2021

Should this be closed as the proposal was implemented under the v11 feature flag?

1reaction
dakahncommented, Aug 19, 2020

Great research @janhassel. I’m all for making this a v11 breaking change. This would go a long way to improve usability.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Toggle Tokens Are a Better Alternative to Checkboxes
Toggle tokens conserve screen space, so you have room for more content, and users don't have to scroll. Checkboxes require vertical stacking, ...
Read more >
Checkbox vs Toggle Switch: 7 Use-Cases of Forms Design
Tapping a toggle switch is a two-step action: selection and execution, whereas checkbox is just selection of an option and its execution usually ......
Read more >
Checkbox and Toggle Switch - When to use which?
A quick comparison of two of the most popular UI elements: Checkbox and Toggle Switch. What's the difference and where to use which?...
Read more >
Checkbox instead of a toggle - Power Platform Community
Solved: I have a SharePoint site with a Yes/No checkbox column. I would prefer to also use a checkbox in my PowerApp rather...
Read more >
Checkbox Vs Toggle Switch - What One Should You Choose
Toggle Switches are meant for instantaneous actions much like the normal switches you use at home to switch on the lights and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found