---
title: RadioCardGroup
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, TokensTable, PropsTable } from '../../src/components'
import { RadioCardGroup } from '@telus-uds/components-web'
import { RadioCardGroup as BaseDocs } from 'docs/@telus-uds/components-base'
import AvailableOnBoth from '../../partials/_platform-considerations-both.mdx'
import NoStylisticVariants from '../../partials/_variants-none.mdx'

# RadioCardGroup

<LibraryInfo figmaLink="https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2F4zJn2Qn6uXOqPP1GVDipy6%2F%25F0%259F%258D%2580-Allium-Components%3Fnode-id%3D458%253A458" />

```jsx live
<RadioCardGroup
  items={[
    {
      title: 'First item',
      content: <Typography>Additional information about the first item.</Typography>
    },
    {
      title: 'Second item',
      content: <Typography>More information about the second item.</Typography>
    },
    {
      title: 'Second item',
      content: (
        <>
          <Typography>Further info on the third item.</Typography>
          <Typography>This info spans two lines.</Typography>
        </>
      )
    }
  ]}
/>
```

## Introduction

A RadioCardGroup renders a group of [RadioCard](radio-card)s, which display
information with a title and separate content section like a card, but may be selected like a radio button.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

Use RadioCardGroup where the user needs to select one item from multiple options, and where those
options need descriptive content beyond a simple single line of text. For example, for choosing
between named options where additional content beyond the name is needed to make a choice.

:::caution

To ensure proper functionality when using RadioCardGroup in a React Native application, it is important to wrap it with a `ScrollView` component. This not only ensures that the component renders correctly but also enables users to scroll through the list of RadioCards seamlessly, especially when the content extends beyond the available screen space.

:::

### Alternatives

- If the options are fairly simple and can be described in a short phrase, consider [Radio](radio-card)
- If the options require additional information but it is supplementary or of interest to only a minority
  of users rather than essential information for a majority, consider [Radio](radio-card)
  with a [Tooltip](tooltip)
- If the options are very simple and can be described in one or two words or numbers, consider
  [ButtonGroup](button-group)
- If selecting an option simply navigates a user to a new page describing that option, rather than saving a
  selection in the current page or form, consider [PreviewCard](preview-card) or
  [StoryCard](story-card) (web only)

### Items

Use the `items` prop to pass an array of objects describing each RadioCard in the group:

- `title`: main text passed to RadioCard's `title` prop
- `content`: React content passed to RadioCard's `children` prop
- `id`: identifier used to store which RadioCard is selected (uses `title` if undefinded)
- `onChange`: optional function called on selection, in addition to updating the group's selection state

```jsx live
<RadioCardGroup
  items={[
    {
      title: 'First item',
      content: <Typography>Additional information about the first item.</Typography>,
      id: 'first',
      onChange: () => alert('First item selected')
    },
    {
      title: 'Second item',
      content: <Typography>Additional information about the second item.</Typography>,
      id: 'second',
      onChange: () => alert('Second item selected')
    }
  ]}
/>
```

### Controlled

The selection state may be controlled by a parent by passing `checkedId` and an `onChange`
function that updates the parent's state. If the component is controlled in this way,
`checkedId` must never be undefined; pass `null` or an empty string if there is no selection.

```jsx live
function ControlledRadioButtonGroup() {
  const [checkedId, setCheckedId] = useState('')
  return (
    <StackView space={3}>
      <Typography>Currently selected: "{checkedId}"</Typography>
      <RadioCardGroup
        checkedId={checkedId}
        onChange={setCheckedId}
        items={[
          { title: 'First item', content: <Typography>More information here.</Typography> },
          { title: 'Second item', content: <Typography>More information here.</Typography> },
          { title: 'Third item', content: <Typography>More information here.</Typography> }
        ]}
      />
    </StackView>
  )
}
```

### Uncontrolled

If `checkedId` is not provided, RadioCardGroup manages its own state. An initial selection may
be provided by passing `initialCheckedId`.

```jsx live
<RadioCardGroup
  initialCheckedId="Second item"
  items={[
    { title: 'First item', content: <Typography>More information here.</Typography> },
    { title: 'Second item', content: <Typography>More information here.</Typography> },
    { title: 'Third item', content: <Typography>More information here.</Typography> }
  ]}
/>
```

### Use in forms

For web forms, the `name` prop may be used to define the name of the group's `<fieldset>` and input
elements, and `legend` may be used to provide a title with `<legend>` type for the fieldset.

```jsx live
<RadioCardGroup
  legend="Choose a product"
  name="product-choice"
  items={[
    {
      title: 'First product',
      id: 'x019',
      content: <Typography>A truly high quality product.</Typography>
    },
    {
      title: 'Second product',
      id: 'y022',
      content: <Typography>Another excellent product.</Typography>
    },
    {
      title: 'Third product',
      id: 'z144',
      content: <Typography>Not as good as the others, to be honest.</Typography>
    }
  ]}
/>
```

### Validation

Validation state may be set by passing 'error' or 'success' to the `validation` prop.

```jsx live
function ValidationExample() {
  const [validation, setValidation] = useState(null)
  const validate = (id) => setValidation(['a', 'c'].includes(id) ? 'success' : 'error')
  return (
    <RadioCardGroup
      legend="Choose 'a' or 'c'"
      onChange={validate}
      validation={validation}
      feedback={validation && `${validation === 'success' ? 'Valid' : 'Invalid'} item chosen.`}
      items={[
        { title: 'Option "a"', id: 'a', content: <Typography>A valid example option.</Typography> },
        {
          title: 'Option "b"',
          id: 'b',
          content: <Typography>An invalid example option.</Typography>
        },
        { title: 'Option "c"', id: 'c', content: <Typography>A valid example option.</Typography> },
        {
          title: 'Option "d"',
          id: 'd',
          content: <Typography>An invalid example option.</Typography>
        }
      ]}
    />
  )
}
```

### A11y guidelines

RadioCardGroup accepts all the common accessibility props, but also sets accessibility role `'radiogroup'`
and controls the accessibility state of children like RadioCard and Feedback based on current state.

RadioCard component accepts all the common accessibility props, but also sets some defaults, including
accessibility role `'radio'` and accessibility state that depends on the other props (`checked`, `inactive`)
or the internal state in case of uncontrolled RadioCard.

### Platform considerations

<AvailableOnBoth />

## Props

<PropsTable base={BaseDocs} />

## Tokens

<TokensTable
  base={BaseDocs}
  component="RadioCardGroup"
  tokensProps={['tokens', 'radioCardTokens']}
/>

## Variants

<NoStylisticVariants />

## Feedback

<Feedback component="RadioCardGroup" />
