Displays a boolean value.
The basic Toggle usage.
Differentiate states by color.
Show an icon inside the thumb with icon, and a different one when checked with checkedIcon.
You can change disabled Toggle with the property disabled.
Capture changes in Toggle.
Put the label and what it does on the left and the Toggle on the right, and name each switch with aria-label.
| Attribute | Description | Type | Accepted values | Default |
|---|---|---|---|---|
| checked | checked or not | boolean | - | - |
| initialChecked | checked or not on initial | boolean | - | false |
| onChange | change event handler | ToggleEvent | - | - |
| type | current type | ToggleTypes | ToggleTypes | default |
| disabled | disable toggle | boolean | - | false |
| icon | icon inside the thumb | ReactNode | - | - |
| checkedIcon | icon when checked, falls back to icon | ReactNode | - | - |
| ... | native props | LabelHTMLAttributes | 'from', 'name', 'className', ... | - |
interface ToggleEventTarget {
checked: boolean
}
export interface ToggleEvent {
target: ToggleEventTarget
stopPropagation: () => void
preventDefault: () => void
nativeEvent: React.ChangeEvent
}
type ToggleTypes =
| 'default'
| 'primary'
| 'secondary'
| 'success'
| 'warning'
| 'error'
| 'info'