---
title: CheckboxCardGroup
---

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

# CheckboxCardGroup

<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
<CheckboxCardGroup
  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 CheckboxCardGroup renders a group of [CheckboxCard](checkbox-card)s, which display
information with a title and separate content section like a card, but may be selected like a checkbox button.

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

## Guidance

Use CheckboxCardGroup 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 CheckboxCardGroup 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 CheckboxCards 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)
- 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)
  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 CheckboxCard in the group:

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

```jsx live
<CheckboxCardGroup
  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 `checkedIds` and an `onChange`
function that updates the parent's state. If the component is controlled in this way,
`checkedIds` must never be undefined; pass `null` or an empty string if there is no selection.

```jsx live
function ControlledCheckboxButtonGroup() {
  const [checkedIds, setCheckedIds] = useState([])
  return (
    <StackView space={3}>
      <Typography>Currently selected: "{checkedIds}"</Typography>
      <CheckboxCardGroup
        checkedIds={checkedIds}
        onChange={setCheckedIds}
        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 `checkedIds` is not provided, CheckboxCardGroup manages its own state. An initial selection may
be provided by passing `initialCheckedIds`.

```jsx live
<CheckboxCardGroup
  initialCheckedIds={['two']}
  items={[
    { title: 'First item', id: 'one', content: <Typography>More information here.</Typography> },
    { title: 'Second item', id: 'two', content: <Typography>More information here.</Typography> },
    { title: 'Third item', id: 'three', 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
<CheckboxCardGroup
  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 = (ids) =>
    setValidation(ids.includes('a') && ids.length === 1 ? 'success' : 'error')
  return (
    <CheckboxCardGroup
      legend="Choose 'a'"
      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>An invalid example option.</Typography>
        },
        {
          title: 'Option "d"',
          id: 'd',
          content: <Typography>An invalid example option.</Typography>
        }
      ]}
    />
  )
}
```

### A11y guidelines

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

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

### Platform considerations

<AvailableOnBoth />

## Props

<PropsTable base={BaseDocs} />

## Tokens

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

## Variants

<NoStylisticVariants />

## Feedback

<Feedback component="CheckboxCardGroup" />
