Selection
Radio group
A radio group asks for exactly one choice from two to five options that stay in view, such as when a reminder should go off.
In kanso-ui as RadioGroup
Web and native
RadioGroup in kanso-ui 0.59.0, for React.
import { RadioGroup } from '@kanso-labs/kanso-ui'A labelled set of radio buttons with one selected value between them.
It follows the Material Design radio button: a 20dp ring inside a 40dp state layer and a 48dp target, with a 10dp dot in primary once selected. The page draws no error state for the button itself, so an invalid group says so through its label and message while the buttons keep their colours.
What you provide
label(required): what the group is for.children: oneRadioper option, each with avalue. ARadiooutside a group has no state to belong to.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The radio buttons, each with a `value` of its own. |
description | string | — | A hint under the group. Replaced by `error` when there is one, so the two never stack. |
error | string | — | The problem with the current selection, in words. Its presence is what puts the group in its error state — the message, the label's colour and `aria-invalid` on the group all follow from it. Outside a `Form` the message line arrives with the message, so the field grows when this does and moves what is under it. A `Form` holds that space from the start; so does a permanent `description`. |
label required | string | — | What the group is for. Required rather than optional: a set of radio buttons with no name is a set a screen reader cannot introduce. |
Also takes the props of Omit<RadioGroupProps$1, 'children' | 'isInvalid' | 'validationBehavior'>.
Parts
Radio(alsoK.Radio): one option.valuenames the entry it stands for,childrenis its label (or passaria-label), anddescriptionis a hint under the label, read with the button. Extends React Aria'sRadioFieldprops, soisDisabledworks per option.
Example
import { Radio, RadioGroup } from '@kanso-labs/kanso-ui'
<RadioGroup label="Label" defaultValue="first">
<Radio value="first">First item</Radio>
<Radio value="second" description="Supporting line">Second item</Radio>
<Radio value="third">Third item</Radio>
</RadioGroup>The design’s classes
k-group, k-group__legend, k-radio, k-mono and k-muted for a detail, and k-radio__reason.
RadioGroup in kanso-ui and react-native-kanso-ui, restyled to this language.