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 color scheme 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
hookuseRadioGroup
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
components. By default, the name
prop of the
RadioGroup takes precedence.
Name | Type | Default | Description |
---|---|---|---|
id | string | The id assigned to input field | |
name | string | The name of the input field in a radio (Useful for form submission) | |
value | string or number | The value to be used in the radio input. This is the value that will be returned on form submission | |
colorScheme | string | The color of the radio when it's checked. This should be one of the color keys in the theme (e.g."green", "red") | |
defaultIsChecked | boolean | If true , the radio will be initially checked | |
isChecked | boolean | If true , the radio will be checked. You'll need to pass onChange to update it's value (since it's now controlled) | |
isFullWidth | boolean | If true , the radio should take up the full width of the parent | |
size | sm , md , lg | md | The size (width and height) of the radio |
isDisabled | boolean | If true , the radio will be disabled | |
isInvalid | boolean | If true , the radio is marked as invalid. Changes style of unchecked state | |
children | React.ReactNode | The children of the radio | |
onChange | function | Function called when the state of the radio changes | |
onBlur | function | Function called when you blur out of the radio | |
onFocus | function | Function called when the radio receive focus | |
aria-label | string | An accessible label for the radio in event there's no visible label or children was passed | |
aria-labelledby | string | Id that points to the label for the radio in event no children was passed |