Beta Preview

RadioGroup

A radio group allows a user to select a single item from a list of mutually exclusive options.

Favorite pet
 
orientation 
 
isDisabled 
Example
RadioGroup.tsx
RadioGroup.css
import {RadioGroup, Radio} from './RadioGroup';

<RadioGroup label="Favorite pet">
  <Radio value="cat">Cat</Radio>
  <Radio value="dog">Dog</Radio>
  <Radio value="dragon">Dragon</Radio>
</RadioGroup>

Value

Use the value or defaultValue prop to set the selected item, and onChange to handle selection changes.

Favorite sport

Current selection: None

import {RadioGroup, Radio} from './RadioGroup';
import {useState} from 'react';

function Example() {
  let [selected, setSelected] = useState(null);

  return (
    <>
      <RadioGroup
        label="Favorite sport"
        value={selected}
        onChange={setSelected}>
        <Radio value="soccer">Soccer</Radio>
        <Radio value="baseball">Baseball</Radio>
        <Radio value="basketball">Basketball</Radio>
      </RadioGroup>
      <p>Current selection: {selected || 'None'}</p>
    </>
  );
}

Forms

Use the name prop to submit the selected radio to the server. Set the isRequired prop to validate that the user selects an option, or implement custom client or server-side validation. See the Forms guide to learn more.

Favorite pet
import {RadioGroup, Radio} from './RadioGroup';
import {Button} from './Button';
import {Form} from 'react-aria-components';

<Form>
  <RadioGroup
    label="Favorite pet"
    name="pet"
    isRequired>
    <Radio value="dog">Dog</Radio>
    <Radio value="cat">Cat</Radio>
    <Radio value="dragon">Dragon</Radio>
  </RadioGroup>
  <Button type="submit" style={{marginTop: 8}}>Submit</Button>
</Form>

API

Shows a radio group component with labels pointing to its parts, including the radio group label, and radio group element containing three radios with input and label elements.CatDogDragonFavorite PetInputRadio group labelRadio groupRadio label