Playground

Radio group

Pick exactly one option from a short list.

  • Built on radix-ui/RadioGroup
  • 2 parts, named exports
  • role=radiogroup with role=radio items; one Tab stop for the group.
  • Arrow keys move and select; Space selects the focused item.
  • Give the group an accessible name with aria-label or aria-labelledby.
  • Styles in one file: checkbox.css

Import

import '@monoline/css';
import {RadioGroup} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add radio-group

It needs radix-ui; install it if your project does not have it:

npm install radix-ui

Usage

import {RadioGroup, RadioGroupItem} from '@monoline/react';

<RadioGroup aria-label="Plan" defaultValue="monthly">
  <RadioGroupItem value="monthly" label="Monthly" />
  <RadioGroupItem value="yearly" label="Yearly" />
</RadioGroup>

Anatomy

Import the parts you need and nest them like this.

import {RadioGroup, RadioGroupItem} from '@monoline/react';

<RadioGroup>
  <RadioGroupItem />
</RadioGroup>

Examples

Basic

Horizontal

Props

RadioGroupItemProps

PropTypeDefaultDescription
labelReactNode–Visible label shown next to the radio. Without it, give the item an `aria-label`.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[aria-invalid="true"]checkbox.css
[data-orientation="horizontal"]checkbox.css
[data-state="checked"]checkbox.css
[data-state="indeterminate"]checkbox.css

CSS classes

ClassStylesheet
.checkboxcheckbox.css
.checkbox-markcheckbox.css
.radiocheckbox.css
.radio-dotcheckbox.css
.radio-groupcheckbox.css
.swcheckbox.css
.sw-thumbcheckbox.css
.choice10-choices.css
.choice-group10-choices.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.checkbox {
  border-color: var(--accent);
}
.checkbox[aria-invalid="true"] {
  background: var(--wash);
}

Accessibility

  • role=radiogroup with role=radio items; one Tab stop for the group.
  • Arrow keys move and select; Space selects the focused item.
  • Give the group an accessible name with aria-label or aria-labelledby.

Keyboard

KeysAction
Arrow keysMove and select
SpaceSelects the focused item