What the component guarantees
- A switch, announced as one. A native
<input type="checkbox" role="switch">, so a reader says "on" and "off" rather than "checked", and the browser handles Space. It is visually hidden inside the track, not removed, so it is in the tab order. - A label tied to it.
labelrenders anNbLabelwhoseforis the input's id.hide-labelhides it visually and keeps it for assistive technology, for a switch whose row already says what it does. - A visible focus ring, 2px of
--nb-c-focus-ringaround the track under:focus-visible. - Disabled is native on the input, with
aria-disabledon the track. - A fingertip target on phones: the
hit-areamixin gives the 32 by 16 track a 44px box on a phone touch screen. A desktop is unchanged. - Tested in
tests/Switch.test.tsand by axe intests/axe.test.ts.
Keyboard
| Key | Action |
|---|---|
| Tab | Moves to the switch |
| Space | Turns it on or off |
What you own
- A label, visible or with
hide-label. Without one the switch is announced as "switch, off" and nothing else. - Immediate effect. A switch says the change happens now. If it only takes effect when a form is saved, use
NbCheckbox. - Announcing a failure. If turning it on fails (a request rejected), revert it and say so with a toast; a switch that quietly flips back is not announced.
Known gaps
verbosedraws ON and OFF as generated content on the track. It is decoration: the state a reader hears comes from the input, not from that text.- No validation props (
error,helper). A switch inside a form that needs a message has to carry it beside the switch, linked by you. - No manual screen reader pass has been recorded for this component.