ChoiceGroup

Organizes checkboxes or radio buttons into a single related group.

To implement ChoiceGroup component into your project you’ll need to add the import:

import ChoiceGroup from "@kiwicom/orbit-components/lib/ChoiceGroup";
import Radio from "@kiwicom/orbit-components/lib/Radio";

After adding import into your project you can use it simply like:

<ChoiceGroup label="What was the reason for your cancellation?">
<Radio label="Reason one" value="one" />
<Radio label="Reason two" value="two" />
<Radio label="Reason three" value="three" />
</ChoiceGroup>

Table below contains all types of the props available in the ChoiceGroup component.

NameTypeDefaultDescription
dataTeststringOptional prop for testing purposes.
childrenReact.NodeThe content of the ChoiceGroup, normally Radio or Checkbox
errorTranslationThe error to display beneath the ChoiceGroup. Also, the Checkboxes/Radios will turn red when you pass some value.
labelTranslationHeading text of the ChoiceGroup
labelAsenum"h4"The element used to render the label into.
labelSizeenum"normal"The size type of Heading.
onChangeevent => void \| PromiseFunction for handling onChange event. See Functional specs
filterbooleanfalseChanges visual appearance of child components, to contain background on hover and updates padding.
onOnlySelection(event, {value: string, label: string}) => void \| Promise<any>Function for handling onOnlySelection, read more in Functional specs.
onlySelectionTextTranslationProperty for passing translation string when you want to use the onOnlySelection callback.
labelElementlabelSize
"h2""normal"
"h3""large"
"h4"
"h5"
"h6"
  • onChange props in <Radio /> or <Checkbox /> will be overrode by internal onChange function
  • If you want to handle selecting field, pass onChange to <ChoiceGroup /> and it will be always triggered when <Radio /> or <Checkbox /> should change
  • onChange will return SyntheticEvent of field that should change
<ChoiceGroup onChange={ev => doSomething(ev)}>
<Radio label="Reason one" value="one" />
<Radio label="Reason two" value="two" />
<Radio label="Reason three" value="three" />
</ChoiceGroup>
  • onOnlySelection can be used only when filter prop is used.
  • filter pattern with onOnlySelection is used where multiple checkboxes in different states are presented to the user, and the user wants to choose only one of them.
  • filter pattern with onOnlySelection shouldn’t contain radio buttons.