<script> import {Switch, Field} from 'ui-ingredients';</script><Field.Root> <Switch.Root> <Switch.Control> <Switch.Thumb /> </Switch.Control> <Switch.Label>Label</Switch.Label> <Switch.HiddenInput /> </Switch.Root> <Field.HelperText>This is a helper text</Field.HelperText> <Field.ErrorText>This is an error text</Field.ErrorText></Field.Root>
API Reference
Root
Prop
Default
Description
checked
booleanThe controlled checked state of the switch
defaultChecked
booleanThe initial checked state of the switch when rendered.
Use when you don't need to control the checked state of the switch.
disabled
booleanWhether the switch is disabled.
form
stringThe id of the form that the switch belongs to
id
stringThe unique identifier of the machine.
ids
{
root?: string;
hiddenInput?: string;
control?: string;
label?: string;
thumb?: string;
}The ids of the elements in the switch. Useful for composition.
invalid
booleanIf `true`, the switch is marked as invalid.
label
stringSpecifies the localized strings that identifies the accessibility elements and their states
name
stringThe name of the input field in a switch
(Useful for form submission).
onCheckedChange
(details: CheckedChangeDetails) => voidFunction to call when the switch is clicked.
readOnly
booleanWhether the switch is read-only
required
booleanIf `true`, the switch input is marked as required,
value
"on"
string | numberThe value of switch input. Useful for form submission.