---
title: CardGroup
---

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

# CardGroup

<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" />

## Roles

CardGroup with role of `radiogroup`, the `radiogroup` role is default.

```jsx live
<CardGroup
  items={[
    {
      id: 'id-1',
      interactiveCard: {
        body: (
          <>
            <Typography block variant={{ size: 'eyebrow' }}>
              Samsung
            </Typography>
            <Spacer space={3} />
            <Typography block variant={{ size: 'h3' }}>
              Galaxy S24 Ultra
            </Typography>
            <Image src={'/universal-design-system/img/pigs-allium-lo.png'} alt="Guinea pig" />
            <Box top={4}>
              <Typography>
                Right now you can get double the memory for no extra cost. Select the 512GB memory
                option and you’ll get it for the same price as the 256GB model.
              </Typography>
            </Box>
          </>
        )
      },
      card: {
        body: (
          <Box space={4} top={3}>
            <Button variant={{ priority: 'high', width: 'full' }}>Add to cart</Button>
          </Box>
        )
      }
    },
    {
      id: 'id-2',
      interactiveCard: {
        body: (
          <>
            <Typography block variant={{ size: 'eyebrow' }}>
              Samsung
            </Typography>
            <Spacer space={3} />
            <Typography block variant={{ size: 'h3' }}>
              Galaxy S24 Ultra
            </Typography>
            <Image src={'/universal-design-system/img/pigs-allium-lo.png'} alt="Guinea pig" />
            <Box top={4}>
              <Typography>
                Right now you can get double the memory for no extra cost. Select the 512GB memory
                option and you’ll get it for the same price as the 256GB model.
              </Typography>
            </Box>
          </>
        )
      },
      card: {
        body: (
          <Box space={4} top={3}>
            <Button variant={{ priority: 'high', width: 'full' }}>Add to cart</Button>
          </Box>
        )
      }
    },
    {
      id: 'id-3',
      interactiveCard: {
        body: (
          <>
            <Typography block variant={{ size: 'eyebrow' }}>
              Samsung
            </Typography>
            <Spacer space={3} />
            <Typography block variant={{ size: 'h3' }}>
              Galaxy S24 Ultra
            </Typography>
            <Image src={'/universal-design-system/img/pigs-allium-lo.png'} alt="Guinea pig" />
            <Box top={4}>
              <Typography>
                Right now you can get double the memory for no extra cost. Select the 512GB memory
                option and you’ll get it for the same price as the 256GB model.
              </Typography>
            </Box>
          </>
        )
      },
      card: {
        body: (
          <Box space={4} top={3}>
            <Button variant={{ priority: 'high', width: 'full' }}>Add to cart</Button>
          </Box>
        )
      }
    }
  ]}
/>
```

CardGroup with role of `checkbox`

```jsx live
<CardGroup
  role="checkbox"
  items={[
    {
      id: 'id-1',
      interactiveCard: {
        body: (
          <>
            <Typography block variant={{ size: 'eyebrow' }}>
              Samsung
            </Typography>
            <Spacer space={3} />
            <Typography block variant={{ size: 'h3' }}>
              Galaxy Buds2 Pro
            </Typography>
            <img src="/universal-design-system/img/lovebirds.jpeg" />
            <Box top={4}>
              <Typography>
                Galaxy Buds2 opens a new world of audio experience with well-balanced sound,
                unmatched comfort fit, ANC, and seamless connectivity to your phone and watch.
              </Typography>
            </Box>
          </>
        )
      },
      card: {
        body: (
          <Box space={4} top={3}>
            <Button variant={{ priority: 'high', width: 'full' }}>Add to cart</Button>
          </Box>
        )
      }
    },
    {
      id: 'id-2',
      interactiveCard: {
        body: (
          <>
            <Typography block variant={{ size: 'eyebrow' }}>
              Samsung
            </Typography>
            <Spacer space={3} />
            <Typography block variant={{ size: 'h3' }}>
              Galaxy Buds2 Pro
            </Typography>
            <img src="/universal-design-system/img/lovebirds.jpeg" />
            <Box top={4}>
              <Typography>
                Galaxy Buds2 opens a new world of audio experience with well-balanced sound,
                unmatched comfort fit, ANC, and seamless connectivity to your phone and watch.
              </Typography>
            </Box>
          </>
        )
      },
      card: {
        body: (
          <Box space={4} top={3}>
            <Button variant={{ priority: 'high', width: 'full' }}>Add to cart</Button>
          </Box>
        )
      }
    },
    {
      id: 'id-3',
      interactiveCard: {
        body: (
          <>
            <Typography block variant={{ size: 'eyebrow' }}>
              Samsung
            </Typography>
            <Spacer space={3} />
            <Typography block variant={{ size: 'h3' }}>
              Galaxy Buds2 Pro
            </Typography>
            <img src="/universal-design-system/img/lovebirds.jpeg" />
            <Box top={4}>
              <Typography>
                Galaxy Buds2 opens a new world of audio experience with well-balanced sound,
                unmatched comfort fit, ANC, and seamless connectivity to your phone and watch.
              </Typography>
            </Box>
          </>
        )
      },
      card: {
        body: (
          <Box space={4} top={3}>
            <Button variant={{ priority: 'high', width: 'full' }}>Add to cart</Button>
          </Box>
        )
      }
    }
  ]}
/>
```

## Introduction

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

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

## Guidance

Use CardGroup where the user needs to select one or more items 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 CardGroup 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 Cards 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 [Checkbox](checkbox-card) or a [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 [Checkbox](checkbox-card) or [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 Card in the group, each Card use the interactive prop:

- `interactiveCard`: React content passed to Card's `children` prop in the interactive part of the Card
- `card`: React content passed to Card's `children` prop
- `id`: identifier used to store which CheckboxCard is selected (uses `title` if undefinded)
- `onPress`: optional function called on selection, in addition to updating the group's selection state

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

### 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 = (ids) =>
    setValidation(ids.includes('a') && ids.length === 1 ? 'success' : 'error')
  return (
    <CardGroup
      role="checkbox"
      onChange={validate}
      validation={validation}
      feedback={validation && `${validation === 'success' ? 'Valid' : 'Invalid'} item chosen.`}
      items={[
        {
          id: 'id-1',
          interactiveCard: {
            body: (
              <>
                <Typography block variant={{ size: 'eyebrow' }}>
                  Apple
                </Typography>
                <Spacer space={3} />
                <Typography block variant={{ size: 'h3' }}>
                  Iphone 16 Pro Max
                </Typography>
                <img src="/universal-design-system/img/guinea-pig.png" />
                <Box top={4}>
                  <Typography>
                    Get the new iPhone 16 Pro Max at a great price with the best promotion: pay for
                    256GB and we'll give you 512GB for free.
                  </Typography>
                </Box>
              </>
            )
          },
          card: {
            body: (
              <Box space={4} top={3}>
                <Button variant={{ priority: 'high', width: 'full' }}>Add to cart</Button>
              </Box>
            )
          }
        },
        {
          id: 'id-2',
          interactiveCard: {
            body: (
              <>
                <Typography block variant={{ size: 'eyebrow' }}>
                  Apple
                </Typography>
                <Spacer space={3} />
                <Typography block variant={{ size: 'h3' }}>
                  Iphone 16 Pro Max
                </Typography>
                <img src="/universal-design-system/img/guinea-pig.png" />
                <Box top={4}>
                  <Typography>
                    Get the new iPhone 16 Pro Max at a great price with the best promotion: pay for
                    256GB and we'll give you 512GB for free.
                  </Typography>
                </Box>
              </>
            )
          },
          card: {
            body: (
              <Box space={4} top={3}>
                <Button variant={{ priority: 'high', width: 'full' }}>Add to cart</Button>
              </Box>
            )
          }
        },
        {
          id: 'id-3',
          interactiveCard: {
            body: (
              <>
                <Typography block variant={{ size: 'eyebrow' }}>
                  Apple
                </Typography>
                <Spacer space={3} />
                <Typography block variant={{ size: 'h3' }}>
                  Iphone 16 Pro Max
                </Typography>
                <img src="/universal-design-system/img/guinea-pig.png" />
                <Box top={4}>
                  <Typography>
                    Get the new iPhone 16 Pro Max at a great price with the best promotion: pay for
                    256GB and we'll give you 512GB for free.
                  </Typography>
                </Box>
              </>
            )
          },
          card: {
            body: (
              <Box space={4} top={3}>
                <Button variant={{ priority: 'high', width: 'full' }}>Add to cart</Button>
              </Box>
            )
          }
        }
      ]}
    />
  )
}
```

### A11y guidelines

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

### Platform considerations

<AvailableOnBoth />

## Props

<PropsTable base={BaseDocs} />

## Tokens

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

## Variants

<NoStylisticVariants />

## Feedback

<Feedback component="CardGroup" />
