components/switch/index.en-US.md
Switch and Checkbox is that Switch will trigger a state change directly when you toggle it, while Checkbox is generally used for state marking, which should work in conjunction with submit operation.<code src="./demo/basic.tsx">Basic</code> <code src="./demo/disabled.tsx">Disabled</code> <code src="./demo/text.tsx">Text & icon</code> <code src="./demo/size.tsx">Two sizes</code> <code src="./demo/loading.tsx">Loading</code> <code src="./demo/component-token.tsx" debug>Custom component token</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code>
Common props ref:Common props
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| checked | Determine whether the Switch is checked | boolean | false | |
| checkedChildren | The content to be shown when the state is checked | ReactNode | - | |
| className | The additional class to Switch | string | - | |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | |
| defaultChecked | Whether to set the initial state | boolean | false | |
| defaultValue | Alias for defaultChecked | boolean | - | 5.12.0 |
| disabled | Disable switch | boolean | false | |
| loading | Loading state of switch | boolean | false | |
| size | The size of the Switch, options: medium small | string | medium | |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | |
| unCheckedChildren | The content to be shown when the state is unchecked | ReactNode | - | |
| value | Alias for checked | boolean | - | 5.12.0 |
| onChange | Trigger when the checked state is changing | function(checked: boolean, event: Event) | - | |
| onClick | Trigger when clicked | function(checked: boolean, event: Event) | - |
| Name | Description |
|---|---|
| blur() | Remove focus |
| focus() | Get focus |
<code src="./demo/_semantic.tsx" simplify="true"></code>
<ComponentTokenTable component="Switch"></ComponentTokenTable>
Form.Item default bind value to value property, but Switch value property is checked. You can use valuePropName to change bind property.
<Form.Item name="fieldA" valuePropName="checked">
<Switch />
</Form.Item>