Skip to content

Radio group

A set of radio buttons for picking exactly one option; a Radio needs a RadioGroup.

import { RadioGroup, Radio } from '@windmorph/react';

Props

By name or description, across the 56 props below

RadioGroup 31 props

  • labeltype ReactNode

    Visible group label.

    One of label, aria-label or aria-labelledby is required.

  • supportingTexttype ReactNode

    Helper text below the options.

  • disabledtype booleandefault false

    Turns every option off: none can be selected or focused.

  • readOnlytype booleandefault false

    The options can be focused but the selection can't change.

  • requiredtype booleandefault false

    An option must be selected before the form submits.

  • invalidtype booleandefault false

    Shows the error state.

  • densitytype 0 | -1 | -2 | -3default 0

    Web density, 0 to -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 nearest ThemeProvider or ThemeScope; M3 asks for density to be the reader's choice, so prefer setting it there.

  • controlPlacementtype "start" | "end"default "start"

    Where each option's radio button sits beside its label: start (before it) or end (after it, the label growing to fill the row). An option's own controlPlacement wins.

  • childrentype ReactNode

    The options: Radio elements.

  • reftype Ref<HTMLDivElement>

    Ref to the root <div> element.

Events

  • onChangetype ((value: string) => void)

    Called with the selected option's value when the selection changes.

Text

  • aria-labeltype string

    Defines a string value that labels the current element.

    One of label, aria-label or aria-labelledby is required.

  • aria-labelledbytype string

    Identifies the element (or elements) that labels the current element.

    One of label, aria-label or aria-labelledby is required.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Radio 25 props

  • valuetype stringRequired

    The value this option selects.

  • disabledtype booleandefault false

    Turns this option off: it can't be selected or focused.

  • densitytype 0 | -1 | -2 | -3default 0

    Web density, 0 to -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 nearest ThemeProvider's or ThemeScope's.

  • controlPlacementtype "start" | "end"default "start"

    Where the radio button sits beside its label: start (before it) or end (after it, the label growing to fill the row). Left out, the group's applies. With end the root carries data-control-placement="end", for styling.

  • reftype Ref<HTMLLabelElement>

    The root <label>. Use inputRef for the radio input.

  • inputReftype Ref<HTMLInputElement>

    Ref to the visually hidden radio <input>.

Text

  • aria-labeltype string

    Defines a string value that labels the current element.

  • aria-labelledbytype string

    Identifies the element (or elements) that labels the current element.

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.

Radio group tokens (md-comp-radio-button)
VariableDefaultPaintsCompose
--md-comp-radio-button-selected-icon-colorvar(--md-sys-color-primary)The ring and dot of a selected radio button.RadioButtonTokens.SelectedIconColor
--md-comp-radio-button-unselected-icon-colorvar(--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.

  • 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.

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-surface on hover, focus and press. Disabled is on-surface at 38%, which also overrides the selected colour.
  • M3 radios have no error colour of their own; an invalid RadioGroup shows its error text instead.
  • The RadioGroup provides the state, arrow keys, the label (text-title-small), supporting / error text and orientation. Its controlPlacement="end" puts every option's radio button after its label (an option's own wins), as a settings row's.