Skip to main content

RadioCardGroup

Library
UDS Base
Repository
github.com/telus/universal-design-system
Package
npmjs.com/package/@telus-uds/components-base
Package version
1.6.1
Loading...

Introduction

import { RadioCardGroup } from '@telus-uds/components-base'

A RadioCardGroup renders a group of RadioCards, which display information with a title and separate content section like a card, but may be selected like a radio button.

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.

Alternatives

  • If the options are fairly simple and can be described in a short phrase, consider Radio
  • 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 with a Tooltip
  • If the options are very simple and can be described in one or two words or numbers, consider ButtonGroup
  • 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 using basic cards with ButtonLink

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

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.

Loading...

Uncontrolled

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

Loading...

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.

Loading...

Validation

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

Loading...

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.

Props

NameTypeDefaultDescription
itemsarrayOf[]Array of objects containing specifics for each RadioCard to be rendered in the group.
tokenscustomSystem tokens prop, see tokens for more details
radioCardTokenscustomOptional theme token overrides for each inner RadioCard component
variantobjectOfSystem variant prop, see variants for more details
legendstringMain text used to describe this group, used in Fieldset's Legend element.
hintstringOptional additional text giving more detail to help a user make a choice.
tooltipstringOptional tooltip text content to include alongside the legend and hint.
validation'error' | 'success'Current validation status of the group, passed to the feedback element if there is one.
feedbackstringIf provided, a Feedback element is rendered containing this text.
initialCheckedIdstringIf provided, the radio card with this id is selected on first render.
checkedIdstringIf not undefined, the radio card with this id is selected (or none is selected if `null`), and the element's selection state will be controlled by its parent using the `onChange` function.
onChangefuncFunction to call on change in selection state. Is required if the selection state is controlled by a parent using checkedId and the input is not readOnly.
readOnlyboolIf true, the radio cards cannot be selected by the user and simply show their current state.
inactiveboolIf true, the radio card cannot be interacted with, elements are set as `disabled` and if the theme supports `inactive` appearances rules, these are applied.
namestringOn Web, this is passed to the `name` attribute of the fieldset and each radio input.