Radio
Wrapper for input type radio
Source
LLM docs
Docs
PackageIcon
Usage
Controlled
Uncontrolled
Radio can be used with uncontrolled forms the same way as a native input[type="radio"].
Set the name and value attributes to include radio value in FormData object on form submission.
To control the initial checked state in uncontrolled forms, use defaultChecked prop.
Example usage of uncontrolled Radio with FormData:
States
Change icon
Change icon color
Disabled state
Pointer cursor
By default, the radio input and label have cursor: default (same as native input[type="radio"]).
To change the cursor to pointer, set cursorType on the theme:
Radio with tooltip
You can change the target element to which the tooltip is attached with refProp:
- If
refPropis not set, the tooltip is attached to the radio input - If
refProp="rootRef"is set, the tooltip is attached to the root element (contains label, input, and other elements)
Add props to the root element
All props passed to the component are forwarded to the input element. If you need to add props to the root element, use wrapperProps. In the following example:
data-testid="wrapper"is added to the root elementdata-testid="input"is added to the input element
Radio.Group component
This is anonymous
Radio.Group disabled state
This is anonymous
Controlled Radio.Group
Radio.Indicator
Radio.Indicator looks exactly the same as the Radio component, but it does not
have any semantic meaning; it's just a visual representation of the radio state. You
can use it in any place where you need to display the radio state without any interaction
related to the indicator. For example, it is useful in cards based on buttons, trees, etc.
Note that Radio.Indicator cannot be focused or selected with the keyboard. It is not
accessible and should not be used as a replacement for the Radio component.
Radio.Card component
Radio.Card component can be used as a replacement for Radio to build custom
cards/buttons/other things that work as radios. The root element of the component
has the role="radio" attribute; it is accessible by default and supports the same
keyboard interactions as input[type="radio"].
You can use Radio.Card with Radio.Group the same way as the Radio component:
Choose a package that you will need in your application
CurrentValue: –
Get element ref
Styles API
Radio supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.
Radio description
Radio error
Component Styles API
Hover over selectors to highlight corresponding elements
Accessibility
Set the aria-label or label prop to make the radio accessible: