Radios are used when only one choice may be selected in a series of options.
Native HTML radios are 100% accessible by default, so we used a very common CSS technique to style the radio.
You can override the colorScheme of the Radio to any color key specified in
theme.colors.
The checkbox comes with 3 sizes.
In some cases, you might need to create components that work like radios but
don't look like radios. Chakra exports useRadio, and useRadioGroup hooks to
help with this scenario. Here's what you need to do:
useRadio hook.useRadioGroup hook to control a group of custom radios.name prop#We recommend passing the name prop to the RadioGroup component, instead of
passing it to each Radio component. By default, the name prop of the
RadioGroup takes precedence.
| Name | Type | Description | Default |
|---|---|---|---|
| colorScheme | string | - | |
| defaultIsChecked | boolean | If `true`, the radio will be initially checked. | - |
| id | string | id assigned to input | - |
| isChecked | boolean | If `true`, the radio will be checked. You'll need to pass `onChange` to update its value (since it is now controlled) | - |
| isDisabled | boolean | If `true`, the radio will be disabled | - |
| isFocusable | boolean | If `true` and `isDisabled` is true, the radio will remain focusable but not interactive. | - |
| isFullWidth | boolean | If `true`, the radio will occupy the full width of its parent container | - |
| isInvalid | boolean | If `true`, the radio button will be invalid. This sets `aria-invalid` to `true`. | - |
| isReadOnly | boolean | If `true`, the radio will be read-only | - |
| isRequired | boolean | If `true`, the radio button will be required. This sets `aria-invalid` to `true`. | - |
| name | string | The name of the input field in a radio (Useful for form submission). | - |
| onChange | ((event: ChangeEvent<HTMLInputElement>) => void) | Function called when checked state of the `input` changes | - |
| orientation | "horizontal" | "vertical" | - | |
| size | string | - | |
| spacing | SystemProps["marginLeft"] | The spacing between the checkbox and its label text | 0.5rem |
| styleConfig | Record<string, any> | - | |
| value | string | number | The value to be used in the radio button. This is the value that will be returned on form submission. | - |
| variant | string | - |