ref | React.Ref<HTMLInputElement>Ref forwarded to the underlying <input> element. |
|---|
label | string · requiredLabel text for the switch (always rendered for accessibility). |
|---|
value | boolean · requiredWhether the switch is on or off. |
|---|
onChange | (checked: boolean, e: ChangeEvent<HTMLInputElement>) => voidCallback fired when the switch state changes. |
|---|
changeAction | (checked: boolean, e: ChangeEvent<HTMLInputElement>) => void | Promise<void>Async action fired after onChange. Triggers optimistic UI and shows a loading spinner until the promise resolves. |
|---|
isLoading | boolean · default falseWhether the switch is in a loading state, showing a spinner inside the thumb. |
|---|
isLabelHidden | boolean · default falseVisually hides the label while keeping it accessible to screen readers. |
|---|
description | stringDescription text displayed below the label. |
|---|
isDisabled | boolean · default falseWhether the switch is disabled. |
|---|
size | 'sm' | 'md' · default 'md'Size variant controlling track and thumb dimensions. sm (32x20px) matches sm checkbox/radio vertical rhythm; md (40x24px, default) matches md checkbox/radio vertical rhythm. |
|---|
htmlName | stringThe HTML name attribute for the underlying checkbox input, useful for form submissions (submits "on" when the switch is on). |
|---|
disabledMessage | stringExplains why the switch is disabled. With isDisabled, shows a tooltip on hover/keyboard focus and keeps the switch focusable via aria-disabled (toggling stays blocked). Use this instead of wrapping a disabled Switch in Tooltip. Disabled controls swallow the hover events an external Tooltip needs. |
|---|
isOptional | boolean · default falseWhether the field is optional. Mutually exclusive with isRequired. |
|---|
isRequired | boolean · default falseWhether the switch is required. Mutually exclusive with isOptional. |
|---|
status | {type: 'warning' | 'error' | 'success', message?: string}Status indicator with type and message. Displays a colored message box below the switch and sets aria-invalid when type is "error". |
|---|
onFocus | (e: FocusEvent<HTMLInputElement>) => voidCallback fired when the switch receives focus. |
|---|
onBlur | (e: FocusEvent<HTMLInputElement>) => voidCallback fired when the switch loses focus. |
|---|
labelIcon | IconTypeIcon displayed before the label text. See astryx docs icons for valid semantic names. |
|---|
labelTooltip | stringTooltip text shown in an info icon at the end of the label. |
|---|
labelPosition | 'start' | 'end' · default 'end'Which side of the switch the label appears on. "start" places the label before the switch. |
|---|
labelSpacing | 'hug' | 'spread' · default 'hug'Spacing behavior between label and switch. "hug" places them next to each other; "spread" pushes them to opposite ends of the container (full width). |
|---|
width | SizeValueWidth of the field (number = pixels, string used as-is, e.g. "100%"). Sizes the whole field (label, control, and status) so they stay aligned. |
|---|