Radio
Radio buttons are a common way to allow users to make a single selection from a list of options. Only one radio button within a group can be selected at a time, so each available choice is its own item / label.
Design guidance
When and how to use this
Use grouped radio buttons if the user is required to choose one and only one item from a list of 2 or more options.
When to consider something else
For cases where the user should be able to return to a โnothing is selectedโ state, or if the user can skip choosing an option altogether, consider using a Select instead.
Figma
Drag in a Radio Field Group from the Compositions section in the Form Controls
v2 library in your Assets pane. We provide default and error states as well as a
required attribute for the field. A Radio Field component is nested within,
which then nests an atomic Radio Button component inside. To set the checked
attribute and state on a button within the Radio Field Group, select the
nested Radio Button and use Figma's component property pane to make changes.
React
Radio composes
Chakraโs Radio. We offer
size variants that align with those in TextInput. We also offer a RadioGroup
that wraps a set of Radio components, controls their values, and distributes
some common props such as size and isDisabled, and a TileRadio that offers
a radio button wrapped in a tile-like element and offers more text styling
options.
| Prop | Description |
|---|---|
size | Sets the size of the Radio and its associated label. |
isChecked | if true, the Radio will be checked. You'll need to pass onChange to update its value (since it is now controlled). |
isDisabled | if true, the Radio will be disabled. |
isInvalid | if true, the Radio will be invalid and its aria-invalid will be set to true. |
Radio Group
Use a RadioGroup for most common radio button set use cases. It uses the same
props as the basic Radio and applies these across each radio button in the
group. In addition you can use the defaultValue prop on this component to set
one of the radio buttons as checked by default.
Size
Radio is available in three sizes and defaults to medium. The size set on
RadioGroup will be distributed to child Radio components.
Filled Variant
Radio is available in an alternative style as the filled variant. However,
the default variant should usually be used in forms, especially alongside
checkboxes.
Color mode
By default, Radio uses the color mode context to determine whether to
display a control for dark or light backgrounds. Pass colorMode to manually
force a color mode.
Radio control
The animated check control that's used in Radio is available as an independent component, for use in custom radios.
Indicator only
Note
Make sure to implement accessibility correctly when using only the indicator
from RadioControl. If the custom component rendering RadioControl is a
checkbox, use useRadio.
With input and useRadio
When using RadioControl directly in a custom radio component that uses
useRadio for its state, pass inputProps and radioProps and
RadioControl will automatically render the hidden <input type="radio"> in
the correct state.
Tile Radio
TileRadio allows for both a label as in the standard Radio component,
but also offers a description prop to set secondary text in the tile. It also
offers an isSubtle prop to remove the border of the element in its default
state. You can wrap a set of TileRadio components in a RadioGroup just like
the standard Radio.
Bootstrap
Bootstrap provides styles for input type=โradioโ and accompanying label
elements, using the .form-check-input and .form-check-label classes wrapped
in a div with the class .form-check. Wrap groups of these in a fieldset
and use the .form-label class on its legend to achieve the same effect as
the React RadioGroup.
| Class | Description |
|---|---|
.form-check-input and .form-check-label | Invokes Bootstrap theme styles for checkboxes and accompanying labels. |
.form-check | Required class on a wrapper div around the checkbox and label elements. |
.form-label | Invokes Bootstrap theme styles for the legend on a fieldset that wraps a .form-check div and its children, as shown above. |