Documentation

Radio group

One choice among a few options, all visible: dots with their words, or whole cards.

WebBêtaFormulaires

Web uniquement — React, depuis @krizaka/ui/radio-group. Bêta : son API peut encore changer à une version mineure.

Quand l’utiliser

  • In a form, to choose exactly one of two to five options that should all be seen: a frequency, a quality.
  • RadioGroup.Card when each option needs more than a line: an amount, a plan, a payment method.

Quand ne pas l’utiliser

  • For many options (a country).À la place : Field
  • For independent options that can all be chosen.À la place : Checkbox
  • To filter a list at once, without a form.À la place : Chip
  • To switch between views.À la place : Tabs

Installation

Installer

npm install @krizaka/ui@beta @krizaka/tailwind@beta @krizaka/tokens@beta tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Importer

import { RadioGroup } from "@krizaka/ui/radio-group";

Exemples

Items

Dots and their words, one disabled.

Cards

Whole cards: the chosen one carries the accent.

Horizontal

orientation="horizontal": the items in a row.

Props

RadioGroupRoot

value/defaultValue + onValueChange, orientation, required, name for a form.

PropTypeDéfautDescription
invalidboolean—Marks every radio invalid: aria-invalid (pair it with a Field.Error).
labelstring—The group's accessible name — passed translated (or aria-labelledby a visible heading).

RadioGroupItem

A radio: a dot, and its words when given.

PropTypeDéfautDescription
childrenReactNode—The words next to the dot, clickable. Otherwise name it with Field.Label htmlFor or aria-label.

Accessibilité

  • Radix RadioGroup: role="radiogroup" named by label, role="radio" with aria-checked on each option.
  • Disabled options are skipped by the arrows.

Clavier

TouchesAction
TabMoves into the group (one tab stop, on the chosen option) and out of it.
Arrow keysMove to the next or previous option and choose it.

Bonnes pratiques

  • Give the group a label: the question being answered.
  • Pre-select the safest or most common option with defaultValue when there is one.
  • Keep the labels parallel and short.

Générée depuis le code de @krizaka/ui 2.0.0-beta.6 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub

Sur cette page