Coming soon! This component will be available in SWAN v3.44.0. Stay tuned!
Choice Group
Use Choice Group...
- When more content flexibility is needed than Radio Group or Checkbox Group can provide.
- For selectable, button-like options (ChoiceButton and ChoiceIconButton).
- For rich content in a selectable container (ChoiceCard).
- For selecting SWAN tile components (ChoiceTile).
- For selectable color swatches (ChoiceColorSwatch).
Don't use Choice Group...
- For simple text-only radio or checkbox lists. Use Radio Group or Checkbox Group instead.
- For a standalone, independent selection. Use Checkbox instead.
Selection Mode
Single
Use selectionMode=”single” to only allow one selection from the group.
The preview has been updated.
Multiple
Use selectionMode=”multiple” to only multiple selections from the group.
The preview has been updated.
Disabled
Use disabled on any Choice subcomponent to prevent it from being selected or deselected. To disable the entire group, use disabled on each item.
The preview has been updated.
Required
Single
Use required on a single Choice subcomponent in the Choice Group to indicate that an option must be selected.
The preview has been updated.
Multiple
Use required on a Choice subcomponent to indicate that this specific option must be selected, such as an agreement the user must accept.
The preview has been updated.
Labels, errors, and helper text
Use the FormField components to add a label, error message, or helper text to a Choice Group. They apply the necessary ARIA attributes for you, so you don't need to add them yourself.
Managing State
Controlled
Single
selectedValue is the value of the currently selected Choice, or an empty string ('') if nothing is selected. onSelectedValueChange receives the newly selected value and the native change event. Update your state in the handler so the group reflects the new selection.
The preview has been updated.
Multiple
selectedValues is an array of the values of the currently selected Choice components, or an empty array ([]) if nothing is selected. onSelectedValuesChange receives the updated array and the native change event. Update your state in the handler so the group reflects the new selection.
The preview has been updated.
Uncontrolled
Omit selectedValue/selectedValues to allow the browser to manage the state. Optionally, use defaultSelectedValue/defaultSelectedValues to set the initially selected value(s), and/or pass onSelectedValueChange/onSelectedValuesChange to react to changes (for example, to track the selection) without taking over the state.
The preview has been updated.
Accessibility
ChoiceGroup must have a localized accessible name.
Use a FormLabel to provide a visible and accessible name (recommended, see Labels, helpers, and error text). Alternatively, use custom ARIA labels (see Accessibility guidelines).
Layout and spacing
ChoiceGroup uses a sensible default layout for its subcomponents. To customize the layout, compose the options inside a FlexBox with gap between-controls, or a nested GridContainer.
The preview has been updated.
Subcomponents
ChoiceButton
Use ChoiceButton for compact choices that should feel like selectable buttons, such as sizes, quantities, or short text options.
The preview has been updated.
ChoiceIconButton
Use ChoiceIconButton for icon-only choices that are universally understood actions such as delete, download, and edit.
The preview has been updated.
Tooltip
Refer to IconButton tooltip for usage guidelines.
ChoiceCard
Use ChoiceCard for richer selectable content.
The preview has been updated.
Indicator
Use indicatorMode and indicatorPosition to customize the visibility and location of the radio or checkbox indicator.
The preview has been updated.
Full Bleed
Use fullBleed to expand the content to the edges of the card.
The preview has been updated.
Even Height
The preview has been updated.
ChoiceTile
Use ChoiceTile to make supported SWAN tile components selectable while preserving tile-specific selected styling. Supported tile components are currently FileTile and components built using BaseTile (e.g. TemplateTile). Do not use ChoiceTile as a general-purpose wrapper for custom content.
The preview has been updated.
Indicator
Use indicatorMode and indicatorPosition to customize the visibility and location of the radio or checkbox indicator.
The preview has been updated.
ChoiceColorSwatch
Use ChoiceColorSwatch inside ColorSwatches when the selectable value is represented by a color swatch. ChoiceColorSwatch takes the same props as ColorSwatch.
The preview has been updated.