Toggle
How it works
The toggle Carbon component is a control that uses a two state checkbox commonly
used to switch between two possible states such as on or off. The Tab key is
used to move focus to each toggle control. Either the Enter or Space key can be
used to toggle between a checked or unchecked positions. The ARIA state
aria-checked="true"
is set when the toggle switch is checked or in the on
position. When the toggle component is unchecked or in the off position, the
ARIA state is set to aria-checked="false"
. A toggle component identified as
disabled is ignored in the tab order.
Accessibility considerations
This component has been validated to meet the WCAG 2.0 AA and Section 508 accessibility guidelines, however changes made by the content owner can affect accessibility compliance. Be sure to review and follow the guidance in this section when updating or adding new content to this component.
- Each toggle control should have a clear and concise label.
- Users should be warned if selecting a toggle component will cause a change in context.
- The
id
for each component must be unique when more then one Carbon toggle component is present on a Web page. - If the toggle is a required field include the aria-required property and indicate that it is a required field and use the validation message for input errors.
Resources
- W3C WAI-ARIA Authoring Practices Accordion Design Pattern covers the usage of ARIA names, state and roles, as well as the expected keyboard interactions.
- IBM Accessibility Requirements:
- 1.3.1 Info and Relationships (WCAG Success Criteria 1.3.1)
- 2.4.6 Headings and Labels (WCAG Success Criteria 2.4.6)
- 3.2.2 On Input (WCAG Success Criteria 3.2.2)
- 4.1.2 Name, Role, Value (WCAG Success Criteria 4.1.2)
Accessibility testing
Accessibility issues are tracked in the Carbon Component GitHub repository.
Automated test
- Chrome version 77.0.3865.90
- Dynamic Assessment Plugin (DAP) version 1.8.0.0 - IBM Accessibility WCAG 2.1 Sept. 2019 Ruleset
- Carbon React version 7.7.1
- No violations
macOS screen reader tests
- Chrome version 77.0.3865.90
- Carbon React version 7.7.1
- Press the Tab key to navigate to the first toggle component. VO announces the label as Off, the state as unchecked, and that it is a checkbox.
- Press the Space key to change the state of the toggle component On and Off.
- Press the Tab key to navigate to the labeled toggle component. VO announces the label as Off, the state as unchecked, that it is a checkbox and the label.
- Press the Tab key and the disabled toggle component is skipped.
- Control-Option-Left arrow key back to the disabled toggle component. VO announces that it is a disabled checkbox, dimmed unchecked checkbox.
- Safari version 13.0.2
- Carbon React version 7.7.1
- Press the Tab key to navigate to the first toggle component. VO announces the label as off, the state as unchecked, and that it is a checkbox.
- Press the Space key to change the state of the toggle component on and off.
- Press the Tab key to navigate to the labeled toggle component. VO announces the label as off, the state as unchecked, that it is a checkbox and the label.
- Press the Tab key and the disabled toggle component is skipped.
- Control-Option-Left arrow key back to the disabled toggle component. VO announces that it is an off, dimmed unchecked checkbox.
Windows screen reader tests
- JAWS 19.1810.64
- Chrome version 73.0.3683.103 (Official Build) (64-bit)
- Carbon React version 7.7.1
- Navigate among the toggle component by pressing the Tab and Shift-Tab keys, or X and Shift+X keys to jump to next or previous checkboxes.
- When navigating to a toggle, JAWS announces the label, checkbox, and the status of the checkbox.
- Disabled toggle components can only be found by using the Up and Down Arrow keys, when JAWS announces "disabled checkbox checkbox unchecked unavailable".
- Press the Space key to select or deselect the toggle. JAWS announces the status of checked or unchecked.
- NVDA version 2018.4.1
- Chrome version 72.0.3683.103 (Official Build) (64-bit)
- Carbon React version 7.7.1
- Navigate among the toggle components by pressing the Tab and Shift-Tab keys, or X and Shift+X keys to jump to next or previous checkboxes.
- When navigating to a toggle, NVDA announces the label, checkbox, and the status of the checkbox, but repeats the information twice.
- Disabled toggle components can only be found by using the Up and Down Arrow keys, or the the X and Shift+X keys. NVDA announces "checkbox unavailable not checked disabled checkbox".
- Press the Space or Enter key to select or deselect the toggle. NVDA announces the status of checked or unchecked.
iOS screen reader tests
- Safari version 13.1.3
- Carbon React version 7.7.1
- Navigate to the toggle components by swiping left or right, or press the Left or Right Arrow keys when quick navigation is turned on. VO announces,the label, field type, and the status of the checkbox.
- When tapping on a toggle, or pressing VO+Space, VoiceOver announces the new status of the toggle component as checked or unchecked.
Android screen reader tests
- Chrome version 72.0.3683.103 (Official Build) (64-bit)
- Carbon React version 7.7.1
- Navigate to the toggle components by swiping left or right, or press the Left or Right Arrow keys. Talkback announces,the label, field type, and the status of the checkbox.
- When tapping on a toggle, or pressing the Alt-Enter keys, Talkback announces the new status of the toggle component as checked or not checked.