Toggle
Used to select between two values.
Import
import { Toggle } from 'rsuite';
// or
import Toggle from 'rsuite/Toggle';
Examples
Default
Size
The size
property sets the switch size, and the value includes: lg
、md
、sm
.
Text and icon
Can be set by the checkedchildren
, uncheckedchildren
two properties, respectively, the display of the toggle state.
Disabled and read only
Loading
Accessibility
Toggle
has roleswitch
.- When "on" state,
Toggle
hasaria-checked
set totrue
. - When "off" state,
Toggle
hasaria-checked
set tofalse
. - All form controls should have labels, which can be implemented in the form through
Form.ControlLabel
. If you need to use it independently, you need to directly add attributes (arial-label
,aria-labelledby
).
<Toggle arial-label="Switch" />
Props
<Toggle>
Property | Type (Default) |
Description |
---|---|---|
checked | boolean | Checked(Controlled) |
checkedChildren | ReactNode | Checked display content |
classPrefix | string 'toggle' |
The prefix of the component CSS class |
defaultChecked | boolean | Default checked |
disabled | boolean | Disabled |
loading | boolean | Whether to show a spinner indicating checked state is being fetched/updated |
locale | ToggleLocaleType | Locale text |
onChange | (checked: boolean, event) => void | Callback function when state changes |
size | 'lg' | 'md' | 'sm' | Toggle size |
unCheckedChildren | ReactNode | Unselected display content |