Version 0.11.2

RadioGroup

A group of radio buttons for selecting one option from a list.

What is your favorite pokemon?

Usage#

import { RadioGroup, Radio } from '@backstage/ui';

<RadioGroup label="Select an option">
  <Radio value="option1">Option 1</Radio>
  <Radio value="option2">Option 2</Radio>
</RadioGroup>

API reference#

RadioGroup#

PropTypeDefaultDescription
label
string
-The visible label for the radio group.
aria-label
string
-Accessible label when a visible label is not provided. Either label, aria-label, or aria-labelledby is required.
aria-labelledby
string
-ID of an element that labels the radio group. Either label, aria-label, or aria-labelledby is required.
secondaryLabel
string
-Secondary label text. Defaults to Required when isRequired is true.
description
string
-Helper text displayed below the label.
orientation
horizontalvertical
verticalThe axis the radio buttons should align with.
value
string
-The current value (controlled).
defaultValue
string
-The default value (uncontrolled).
onChange
(value: string) => void
-Handler called when the value changes.
name
string
-The name of the radio group for form submission.
isDisabled
boolean
-Whether all radio buttons in the group are disabled.
isReadOnly
boolean
-Whether the radio group is read-only.
isRequired
boolean
-Whether a selection is required before form submission.
isInvalid
boolean
-Whether the radio group is in an invalid state.
children
ReactNode
-
className
string
-Additional CSS class name for custom styling.

Inherits all React Aria RadioGroup props.

Radio#

Individual radio button within a group.

PropTypeDefaultDescription
value
string
-The value of the radio button.
isDisabled
boolean
-Whether this radio button is disabled.
children
ReactNode
-
className
string
-Additional CSS class name for custom styling.

Inherits all React Aria Radio props.

Examples#

Horizontal#

<RadioGroup
  label="What is your favorite pokemon?"
  orientation="horizontal"
>
  <Radio value="bulbasaur">Bulbasaur</Radio>
  <Radio value="charmander">Charmander</Radio>
  <Radio value="squirtle">Squirtle</Radio>
</RadioGroup>
What is your favorite pokemon?

Disabled#

<RadioGroup label="What is your favorite pokemon?" isDisabled>
  <Radio value="bulbasaur">Bulbasaur</Radio>
  <Radio value="charmander">Charmander</Radio>
  <Radio value="squirtle">Squirtle</Radio>
</RadioGroup>
What is your favorite pokemon?

Disabled single radio#

<RadioGroup label="What is your favorite pokemon?">
  <Radio value="bulbasaur">Bulbasaur</Radio>
  <Radio value="charmander" isDisabled>
    Charmander
  </Radio>
  <Radio value="squirtle">Squirtle</Radio>
</RadioGroup>
What is your favorite pokemon?

Validation#

<RadioGroup
  label="What is your favorite pokemon?"
  name="pokemon"
  defaultValue="charmander"
  validationBehavior="aria"
  validate={value => (value === 'charmander' ? 'Nice try!' : null)}
>
  <Radio value="bulbasaur">Bulbasaur</Radio>
  <Radio value="charmander">Charmander</Radio>
  <Radio value="squirtle">Squirtle</Radio>
</RadioGroup>
What is your favorite pokemon?
Nice try!

Read only#

<RadioGroup
  label="What is your favorite pokemon?"
  isReadOnly
  defaultValue="charmander"
>
  <Radio value="bulbasaur">Bulbasaur</Radio>
  <Radio value="charmander">Charmander</Radio>
  <Radio value="squirtle">Squirtle</Radio>
</RadioGroup>
What is your favorite pokemon?

Theming#

Our theming system is based on a mix between CSS classes, CSS variables and data attributes. If you want to customise this component, you can use one of these class names below.

  • bui-RadioGroup
  • bui-RadioGroupContent
  • bui-Radio

Changelog#

Version 0.9.0#

Changes

  • Fixed RadioGroup radio button ellipse distortion by preventing flex shrink and grow. #31576