Switch Preview
A switch lets someone choose between two mutually exclusive options, like on or off. Activating a switch triggers an immediate change.
If you need a component that requires a submission step before applying a change, or if you need to specify an indeterminate state, try a checkbox.
Properties
as
“input”
checked
Defines the controlled checked state of the Switch. If passed, Switch ignores the
defaultChecked
property. This should only be used if the checked state is to be controlled at a higher level and there is a plan to pass the correct value based on handling
onChange
events and re-rendering.
boolean
false
defaultChecked
Defines whether the Switch is initially in a checked state or not when rendered.
boolean
false
indicator
The track and the thumb sliding over it indicating the on and off status of the Switch.
WithSlotShorthandValue<{ as?: "div"; } & Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof HTMLAttributes<...>> & { ...; } & { ...; }>
input
Hidden input that handles the Switch’s functionality.
This is the PRIMARY slot: all native properties specified directly on the
tag will be applied to this slot, except
<Switch>
className
and
style
, which remain on the root slot.
({ as?: "input"; } & Omit<Pick<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "key" | keyof InputHTMLAttributes<...>> & { ...; }, "children"> & { ...; })
label
The Switch’s label.
WithSlotShorthandValue<WithSlotRenderFunction<Omit<ComponentProps<LabelSlots, "root">, "required"> & { disabled?: boolean; required?: boolean | WithSlotShorthandValue<{ as?: "span"; } & Pick<...> & { ...; } & { ...; }> | null | undefined; size?: "small" | ... 2 more ... | undefined; weight?: ...
labelPosition
The position of the label relative to the Switch.
“before”
“after”
“above”
“after”
onChange
Callback to be called when the checked state value changes.
((ev: ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void)
root
The root element of the Switch.
The root slot receives the
className
and
style
specified directly on the
tag. All other native props will be applied to the primary slot:
<Switch>
input
.
WithSlotShorthandValue<{ as?: "div"; } & Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof HTMLAttributes<...>> & { ...; } & { ...; }>