formsswitch
Switch
Toggle switch control with icon slots and loading state.
Import#
Slot Structure#
Toggle track with thumb and optional label area.
Examples#
Basic + Controlled#
Uncontrolled and controlled switch with icon slots.
Variants#
Loading, disabled, and explicit icon combinations.
Sizes#
Switch size scale from xs to xl.
Custom True/False Values#
Map checked state to domain values instead of boolean.
API Reference#
Attributes#
Slot
root0 attributesSwitch wrapper that coordinates input, track, thumb, and text content.
No attribute metadata for this slot.
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | TTrue | TFalse | undefined | — | Whether the switch is checked. |
| checkedIcon | IconT.Name | — | Icon shown when the switch is checked. |
| class | ClassValue | — | Class applied to the component root or trigger element. |
| classes | SwitchT.Classes | undefined | — | — |
| defaultChecked | boolean | undefined | — | Whether the switch is checked by default. |
| description | JSX.Element | — | Description for the switch. |
| disabled | boolean | undefined | false | Whether the input is disabled. |
| falseValue | TFalse | undefined | false | Value to use when the switch is unchecked. |
| id | string | undefined | — | The ID of the input element. |
| label | JSX.Element | — | Label for the switch. |
| loading | boolean | undefined | false | Whether the switch is in a loading state. |
| loadingIcon | IconT.Name | icon-loading | Icon shown during loading state. |
| name | string | undefined | — | The name of the input element, used for form submission. |
| onChange | ((value: TTrue | TFalse) => void) | undefined | — | Callback when the switch state changes. |
| onPointerDown | JSX.EventHandlerUnion<HTMLButtonElement, PointerEvent> | undefined | — | Pointer down handler for the switch root container. |
| readOnly | boolean | undefined | false | Whether the input is read-only. |
| ref | JSX.HTMLElementTags["div"] extends { ref?: infer Ref; } ? Ref : never | undefined | — | — |
| required | boolean | undefined | false | Whether the input is required. |
| size | "xs" | "sm" | "md" | "lg" | "xl" | undefined | — | — |
| style | JSX.CSSProperties | undefined | — | — |
| styles | SwitchT.Styles | undefined | — | — |
| trueValue | TTrue | undefined | true | Value to use when the switch is checked. |
| uncheckedIcon | IconT.Name | — | Icon shown when the switch is unchecked. |
| value | string | undefined | on | Native value submitted when the switch is checked. |