Switch toggles a setting between on and off states.
Click or press Space/Enter to toggle. Screen readers announce "on" or "off" via role="switch".
<Field id='basic-switch'>
<Field.Label>Enable feature</Field.Label>
<Switch />
</Field>Parent manages the checked state. External controls can change the value.
const [checked, setChecked] = useState(false);
<Field id='controlled-switch'>
<Field.Label>Dark mode</Field.Label>
<Switch
checked={checked}
onChange={(nextChecked) => setChecked(nextChecked)}
/>
</Field>Switch that starts in the "on" state.
<Field id='default-checked-switch'>
<Field.Label>Notifications</Field.Label>
<Switch defaultChecked />
</Field>Disabled switches cannot be toggled. Screen readers announce the disabled state.
<Field id='disabled-off' disabled>
<Field.Label>Disabled (off)</Field.Label>
<Switch />
</Field>
<Field id='disabled-on' disabled>
<Field.Label>Disabled (on)</Field.Label>
<Switch defaultChecked />
</Field>Focusable but state cannot be changed. Uses aria-readonly.
<Field id='readonly-switch' readOnly>
<Field.Label>Read-only (on)</Field.Label>
<Switch defaultChecked />
</Field>Switch marked as required for form validation. Uses aria-required.
<Field id='required-switch' required>
<Field.Label>Agree to terms</Field.Label>
<Switch />
</Field>