Radio group
A set of radio buttons for picking exactly one option; a Radio needs a RadioGroup.
import { RadioGroup, Radio } from '@windmorph/react';Props
RadioGroup 31 props
Visible group label.
One of
label,aria-labeloraria-labelledbyis required.Helper text below the options.
Turns every option off: none can be selected or focused.
The options can be focused but the selection can't change.
An option must be selected before the form submits.
Shows the error state.
Web density,
0to-3, for every option: each step takes 4px off their round state layers (40px at 0, 28px at -3), while the rows stay 48px apart, so each option keeps a 48px touch target that never overlaps the next one's. Left out, the group takes the density of the nearestThemeProviderorThemeScope; M3 asks for density to be the reader's choice, so prefer setting it there.Where each option's radio button sits beside its label:
start(before it) orend(after it, the label growing to fill the row). An option's owncontrolPlacementwins.The options:
Radioelements.Ref to the root
<div>element.
Events
Called with the selected option's value when the selection changes.
Text
Defines a string value that labels the current element.
One of
label,aria-labeloraria-labelledbyis required.Identifies the element (or elements) that labels the current element.
One of
label,aria-labeloraria-labelledbyis required.
Classes for the root element, merged with
classNames.root; consumer classes win.Classes for each part, by slot.
classNames.rootis merged withclassName.The group's outer element.
The visible group label.
The wrapper around the radio buttons.
The helper text below the options.
The error message, shown in place of the helper text while invalid.
Inline styles for the root element.
The name of the input element, used when submitting an HTML form. See MDN.
The axis the radio buttons should align with.
The current value (controlled).
The default value (uncontrolled).
Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.
A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if
validationBehavior="native". For realtime validation, use theinvalidprop instead.An error message for the field.
Handler that is called when the element receives focus.
Handler that is called when the element loses focus.
Handler that is called when the element's focus status changes.
The
<form>element to associate the input with. The value of this attribute must be the id of a<form>in the same document. See MDN.The element's unique identifier. See MDN.
Identifies the element (or elements) that describes the object.
Identifies the element (or elements) that provide a detailed, extended description for the object.
Identifies the element that provides an error message for the object.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Radio 25 props
The value this option selects.
Turns this option off: it can't be selected or focused.
Web density,
0to-3: each step takes 4px off the round state layer (40px at 0, 28px at -3); the ring stays 20px and the touch target 48px. Left out, the option takes its group's density, or the nearestThemeProvider's orThemeScope's.Where the radio button sits beside its label:
start(before it) orend(after it, the label growing to fill the row). Left out, the group's applies. Withendthe root carriesdata-control-placement="end", for styling.The root
<label>. UseinputReffor the radio input.Ref to the visually hidden radio
<input>.
Text
Defines a string value that labels the current element.
Identifies the element (or elements) that labels the current element.
Classes for the root
<label>, merged withclassNames.root; consumer classes win.Classes for each part, by slot.
classNames.rootis merged withclassName.The outer ring.
The dot inside the ring while selected.
The root
<label>that holds the control and its label text.The 40px control that carries the state layer and holds the indicator.
The label text beside the control.
Inline styles for the root
<label>.
Handler that is called when the element receives focus.
Handler that is called when the element loses focus.
Handler that is called when the element's focus status changes.
The element's unique identifier. See MDN.
Identifies the element (or elements) that describes the object.
Identifies the element (or elements) that provide a detailed, extended description for the object.
Handler that is called when a key is pressed.
Handler that is called when a key is released.
Whether the element should receive focus on render.
Handler that is called when the press is released over the target.
Handler that is called when a press interaction starts.
Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
Handler that is called when the press state changes.
Handler that is called when a press is released over the target, regardless of whether it started on the target or not.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Tokens
M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.
| Variable | Default | Paints | Compose |
|---|---|---|---|
--md-comp-radio-button-selected-icon-color | var(--md-sys-color-primary) | The ring and dot of a selected radio button. | RadioButtonTokens.SelectedIconColor |
--md-comp-radio-button-unselected-icon-color | var(--md-sys-color-on-surface-variant) | The ring of an unselected radio button. | RadioButtonTokens.UnselectedIconColor |
Spec status
Built to the M3 Expressive radio group spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| Selected and unselected | Built | Configuration · Basic |
| Disabled | Built | Configuration · States |
| Choose one option from a set | Built | Use case · Basic, Horizontal |
| Density (web, chosen by the reader) | Built | Use case · Density |
| Group label, supporting and error text | Extension | M3 radios have no error colour, so RadioGroup carries the group's label, supporting text and error message. |
orientation | Extension | Lays the options out in a column or a row; the arrow keys move the selection either way, and in a row Left and Right follow the reading direction. |
Selected and unselected
BuiltConfiguration · Basic
Disabled
BuiltConfiguration · States
Choose one option from a set
BuiltUse case · Basic, Horizontal
Density (web, chosen by the reader)
BuiltUse case · Density
Group label, supporting and error text
ExtensionM3 radios have no error colour, so
RadioGroupcarries the group's label, supporting text and error message.
ExtensionorientationLays the options out in a column or a row; the arrow keys move the selection either way, and in a row Left and Right follow the reading direction.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
RadioGroup,Radio: 16.2 kB
Differences from Compose
- A 20px ring with a 2px stroke; the 10px dot grows on the fast spatial spring and recolours on default effects.
- The unselected ring darkens to
on-surfaceon hover, focus and press. Disabled ison-surfaceat 38%, which also overrides the selected colour. - M3 radios have no error colour of their own; an invalid
RadioGroupshows its error text instead. - The
RadioGroupprovides the state, arrow keys, the label (text-title-small), supporting / error text andorientation. ItscontrolPlacement="end"puts every option's radio button after its label (an option's own wins), as a settings row's.