Radio group
Pick exactly one option from a short list.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | – | 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.
| Attribute | Stylesheet |
|---|---|
[aria-invalid="true"] | checkbox.css |
[data-orientation="horizontal"] | checkbox.css |
[data-state="checked"] | checkbox.css |
[data-state="indeterminate"] | checkbox.css |
CSS classes
| Class | Stylesheet |
|---|---|
.checkbox | checkbox.css |
.checkbox-mark | checkbox.css |
.radio | checkbox.css |
.radio-dot | checkbox.css |
.radio-group | checkbox.css |
.sw | checkbox.css |
.sw-thumb | checkbox.css |
.choice | 10-choices.css |
.choice-group | 10-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
| Keys | Action |
|---|---|
| Arrow keys | Move and select |
| Space | Selects the focused item |