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: one Radio per option, each with a value. A Radio outside a group has no state to belong to.

Props

PropTypeDefaultDescription
childrenReactNode—The radio buttons, each with a `value` of its own.
descriptionstring—A hint under the group. Replaced by `error` when there is one, so the two never stack.
errorstring—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 requiredstring—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 (also K.Radio): one option. value names the entry it stands for, children is its label (or pass aria-label), and description is a hint under the label, read with the button. Extends React Aria's RadioField props, so isDisabled works 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.