An on or off control for a setting that applies straight away.
import { Switch } from '@oztix/roadie-components/switch'
<Switch label='Email me when tickets go on sale' />
The row fills its container, with the label on the left and the switch on the
right. Add className='justify-start' to keep them together.
Add description for a second line. It is announced as the switch's
description, not as part of its name.
<div className='grid max-w-xs gap-3'> <Switch size='sm' label='Small' defaultChecked /> <Switch size='md' label='Medium' defaultChecked /> </div>
Inside Field, Switch takes invalid, required and
disabled from the field, and is described by Field.HelperText or
Field.ErrorText.
Field.Label names a bare switch, and clicking the label toggles it.
<Field className='max-w-md'> <Field.Label>Resale listings</Field.Label> <Switch /> <Field.HelperText>Let fans buy tickets you can no longer use.</Field.HelperText> </Field>
Switch renders its own thumb. Pass Switch.Thumb as a child to style it.
<Switch aria-label='Dark mode'> <Switch.Thumb className='shadow-md' /> </Switch>
Tab moves focus to the switch. Space or Enter toggles it.role="switch" with aria-checked, plus a hidden
checkbox so the value submits with a form.label, Field.Label, or
aria-label on a bare switch.aria-checked carries the
state.The id of the hidden input element. When `nativeButton` is `true`, the id is applied to the root element.
Whether the switch is currently active. To render an uncontrolled switch, use the `defaultChecked` prop instead.
Whether the switch is initially active. To render a controlled switch, use the `checked` prop instead.
Defaults to false.
Whether the component should ignore user interaction.
Defaults to false.
A ref to access the hidden `<input>` element.
Identifies the field when a form is submitted.
Identifies the form that owns the hidden input. Useful when the switch is rendered outside the form.
Event handler called when the switch is activated or deactivated.
Whether the user should be unable to activate or deactivate the switch.
Defaults to false.
Whether the user must activate the switch before submitting a form.
Defaults to false.
The value submitted with the form when the switch is on. By default, switch submits the "on" value, matching native checkbox behavior.
The value submitted with the form when the switch is off. By default, unchecked switches do not submit any value, matching native checkbox behavior.
CSS class applied to the element, or a function that returns a class based on the component's state.
Defaults to 'md'.
Renders a label beside the switch. With `label` or `description`, `className` goes on the row.
Secondary text under the label, announced as the description.
Marks the switch invalid. Inherits from `Field` when unset.
Inherited from NonNativeButtonProps
Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button.
Defaults to false.
No additional props. It forwards all standard HTML attributes to the underlying element.