Switch
Toggle an on/off setting with switch semantics and form values.
Use Switch for an on/off setting whose state is immediately meaningful. For an independent form choice that may be part of a set, use Checkbox.
Basic usage#
Playground#
Anatomy#
Usage#
Checked state and forms#
The focusable button exposes role="switch"; a hidden checkbox handles native form submission.
Use checked with onCheckedChange for controlled state, or defaultChecked for an initial value.
trueValue and falseValue map checked state to domain values for callbacks and schema-bound
forms. Native form submission uses the separate value prop only while checked; an unchecked
switch contributes no entry.
Loading ownership#
loading is visual state supplied by the application. It does not represent an asynchronous operation on its own; decide whether the switch should also be disabled while that operation is pending.
Examples#
Controlled state#
Custom true and false values#
Loading icons#
Form integration#
Attributes#
data-checkedSlot: switch, switch-track, switch-thumb, switch-iconDescription: Present when the item or toggle is checked.data-disabledSlot: switch, switch-track, switch-thumbDescription: Present when the component, slot, or item is disabled.data-invalidSlot: switch, switch-trackDescription: Present when the field or form has a validation error.data-loadingSlot: switch, switch-iconDescription: Present when the component or async operation is loading.data-readonlySlot: switch, switch-trackDescription: Present when the field is in read-only mode.data-requiredSlot: switch, switch-labelDescription: Present when the field input is required.data-uncheckedSlot: switch, switch-track, switch-thumb, switch-iconDescription: Present when the checkbox, radio item, or switch is unchecked.Props#
Props for the Switch component. Renders a <div> element by default.