Switch
A control that allows the user to toggle between checked and not checked.
Code
import { Label, Switch } from "@falcon/ui-kit";
export function Example() { return ( <div className="tw:flex tw:items-center tw:space-x-2"> <Switch id="automatic-substitutions" /> <Label htmlFor="automatic-substitutions">Automatic substitutions</Label> </div> );}Description
Section titled “Description”Code
import { Field, FieldContent, FieldDescription, FieldLabel, Switch,} from "@falcon/ui-kit";
export function Example() { return ( <Field orientation="horizontal" className="tw:max-w-sm"> <FieldContent> <FieldLabel htmlFor="switch-inventory-updates"> Share inventory updates </FieldLabel> <FieldDescription id="inventory-updates-description"> Inventory updates are shared across locations and stop when syncing is disabled. </FieldDescription> </FieldContent> <Switch id="switch-inventory-updates" aria-describedby="inventory-updates-description" /> </Field> );}Choice Card
Section titled “Choice Card”Card-style selection where FieldLabel wraps the entire Field for a clickable
card pattern.
Code
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldTitle, Switch,} from "@falcon/ui-kit";
export function Example() { return ( <FieldGroup className="tw:w-full tw:max-w-sm"> <FieldLabel htmlFor="switch-inventory-updates"> <Field orientation="horizontal"> <FieldContent> <FieldTitle>Share inventory updates</FieldTitle> <FieldDescription> Inventory updates are shared across locations and stop when syncing is disabled. </FieldDescription> </FieldContent> <Switch id="switch-inventory-updates" /> </Field> </FieldLabel> <FieldLabel htmlFor="switch-order-notifications"> <Field orientation="horizontal"> <FieldContent> <FieldTitle>Enable order notifications</FieldTitle> <FieldDescription> Receive notifications when an order needs attention. </FieldDescription> </FieldContent> <Switch id="switch-order-notifications" defaultChecked /> </Field> </FieldLabel> </FieldGroup> );}Disabled
Section titled “Disabled”Add the disabled prop to the Switch component to disable the switch. Add the
data-disabled prop to the Field component for styling.
Code
import { Field, FieldLabel, Switch } from "@falcon/ui-kit";
export function Example() { return ( <Field orientation="horizontal" data-disabled className="tw:w-fit"> <Switch id="switch-disabled-unchecked" disabled /> <FieldLabel htmlFor="switch-disabled-unchecked">Disabled</FieldLabel> </Field> );}Invalid
Section titled “Invalid”Add the aria-invalid prop to the Switch component to indicate an invalid
state. Add the data-invalid prop to the Field component for styling.
Code
import { Field, FieldContent, FieldDescription, FieldLabel, Switch,} from "@falcon/ui-kit";
export function Example() { return ( <Field orientation="horizontal" className="tw:max-w-sm" data-invalid> <FieldContent> <FieldLabel htmlFor="switch-order-terms"> Accept order terms and conditions </FieldLabel> <FieldDescription id="order-terms-description"> You must accept the order terms and conditions to continue. </FieldDescription> </FieldContent> <Switch id="switch-order-terms" aria-describedby="order-terms-description" aria-invalid /> </Field> );}Use the size prop to change the size of the switch.
Code
import { Field, FieldGroup, FieldLabel, Switch } from "@falcon/ui-kit";
export function Example() { return ( <FieldGroup className="tw:w-full tw:max-w-[10rem]"> <Field orientation="horizontal"> <Switch id="switch-size-sm" size="sm" /> <FieldLabel htmlFor="switch-size-sm">Small</FieldLabel> </Field> <Field orientation="horizontal"> <Switch id="switch-size-default" size="default" /> <FieldLabel htmlFor="switch-size-default">Default</FieldLabel> </Field> </FieldGroup> );}Switch
Section titled “Switch”Toggles a setting on or off. Renders a <span> element with a hidden
<input>. The required thumb is built in, so the component does not accept
children.
checked
Section titled “checked”checked?: booleanWhether the switch is currently active. Use defaultChecked for
uncontrolled state.
className
Section titled “className”className?: string | ((state: SwitchRootState) => string | undefined)CSS class applied to the switch, or a function based on its state.
defaultChecked
Section titled “defaultChecked”defaultChecked?: booleanWhether the switch is initially active. Use checked for controlled state.
disabled
Section titled “disabled”disabled?: booleanWhether the switch ignores user interaction.
form?: stringIdentifies the form that owns the hidden input.
id?: stringID of the hidden input, or of the root when nativeButton is true.
inputRef
Section titled “inputRef”inputRef?: React.Ref<HTMLInputElement>Ref to the hidden input element.
name?: stringIdentifies the field when a form is submitted.
nativeButton
Section titled “nativeButton”nativeButton?: booleanWhether render produces a native <button> element.
onCheckedChange
Section titled “onCheckedChange”onCheckedChange?: ((checked: boolean, eventDetails: SwitchPrimitive.Root.ChangeEventDetails) => void)Event handler called when the switch is activated or deactivated.
readOnly
Section titled “readOnly”readOnly?: booleanWhether users can activate or deactivate the switch.
render
Section titled “render”render?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SwitchRootState>Allows replacing the switch element or composing it with another component.
required
Section titled “required”required?: booleanWhether users must activate the switch before submitting the form.
size?: "sm" | "default" = "default"Control size. Defaults to "default".
style?: React.CSSProperties | ((state: SwitchRootState) => React.CSSProperties | undefined)Style applied to the switch, or a function based on its state.
uncheckedValue
Section titled “uncheckedValue”uncheckedValue?: stringValue submitted when the switch is off.
value?: stringValue submitted when the switch is on.