Radio
A radio group for choosing exactly one option, with arrow-key navigation.
Use a radio group when people must choose exactly one of a few options and should see them all at once. For longer lists, use a select.
You can change plans at any time.
import { Radio, RadioGroup } from "@aloxe/react";
export default function RadioBasic() {
return (
<RadioGroup
label="Plan"
name="plan"
defaultValue="team"
description="You can change plans at any time."
>
<Radio value="personal" label="Personal, 1 seat" />
<Radio value="team" label="Team, up to 10 seats" />
<Radio value="enterprise" label="Enterprise, unlimited seats" />
</RadioGroup>
);
}Installation
npm i @aloxe/react @aloxe/tokensThen add the CSS imports from Installation.
Usage
import { Radio, RadioGroup } from "@aloxe/react";
<RadioGroup label="Plan" name="plan" defaultValue="team">
<Radio value="personal" label="Personal" />
<Radio value="team" label="Team" />
</RadioGroup>RadioGroup renders a <fieldset> whose legend is label. Each Radio needs a value and a label.
Examples
Horizontal
orientation="horizontal" lays the options out in a row that wraps on narrow screens. Keep it for short labels.
import { Radio, RadioGroup } from "@aloxe/react";
export default function RadioHorizontal() {
return (
<RadioGroup label="Density" defaultValue="comfortable" orientation="horizontal">
<Radio value="compact" label="Compact" />
<Radio value="comfortable" label="Comfortable" />
<Radio value="spacious" label="Spacious" />
</RadioGroup>
);
}States
An error on the group, and a single disabled option.
import { Radio, RadioGroup } from "@aloxe/react";
export default function RadioStates() {
return (
<div className="flex flex-col gap-8">
<RadioGroup label="Billing period" error="Choose a billing period.">
<Radio value="monthly" label="Monthly" />
<Radio value="yearly" label="Yearly" />
</RadioGroup>
<RadioGroup label="Region" defaultValue="eu">
<Radio value="eu" label="Europe" />
<Radio value="us" label="United States" />
<Radio value="ap" label="Asia Pacific (full)" disabled />
</RadioGroup>
</div>
);
}Controlled
Pass value and onValueChange to react to the choice, such as updating a price.
Shipping: Free
"use client";
import { Radio, RadioGroup } from "@aloxe/react";
import { useState } from "react";
type Delivery = "standard" | "express";
export default function RadioControlled() {
const [delivery, setDelivery] = useState<Delivery>("standard");
return (
<div className="flex flex-col gap-3">
<RadioGroup<Delivery>
label="Delivery"
value={delivery}
onValueChange={(value) => setDelivery(value)}
>
<Radio value="standard" label="Standard, 3 to 5 days" />
<Radio value="express" label="Express, next day" />
</RadioGroup>
<p className="aloxe-text-body-sm text-ax-text-secondary">
Shipping: {delivery === "express" ? "€12.00" : "Free"}
</p>
</div>
);
}Accessibility
| Key | Action |
|---|---|
| Tab | Moves focus into the group, onto the checked radio (or the first one), and then out of the group. |
| Down or Right | Moves to the next option and checks it. |
| Up or Left | Moves to the previous option and checks it. |
| Space | Checks the focused option if it isn't checked. |
- Follows the WAI-ARIA radio group pattern: one tab stop for the whole group.
- The legend names the group, and each label names its radio.
- An error on the group sets
aria-invalidand is linked to it.
API reference
Every part accepts className and renders a data-aloxe attribute you can target in CSS, such as [data-aloxe="radio"].
RadioGroup
Extends Base UI RadioGroup.
| Prop | Type | Default | Description |
|---|---|---|---|
| label (required) | ReactNode | The group's legend. It names the group for screen readers. | |
| value | Value | Controlled value. Pair with onValueChange. | |
| defaultValue | Value | Initial value when uncontrolled. | |
| onValueChange | (value: Value, details) => void | Called when the user picks an option. | |
| orientation | "vertical" | "horizontal" | "vertical" | Stacks the options or lays them out in a wrapping row. |
| showLabel | boolean | true | false hides the legend visually only. |
| description | ReactNode | Supporting text under the legend. | |
| error | ReactNode | Error message, e.g. "Choose a plan". Sets aria-invalid. | |
| disabled | boolean | false | Disables every option. |
| name | string | Form field name. | |
| required | boolean | false | Requires a choice before the form submits. |
| className | string | Classes for the wrapper. |
Radio
Extends Base UI Radio.Root.
| Prop | Type | Default | Description |
|---|---|---|---|
| value (required) | Value | The value this option selects. | |
| label (required) | ReactNode | The visible label and the radio's accessible name. | |
| showLabel | boolean | true | false hides the label visually only. |
| disabled | boolean | false | Disables this option only. |
| className | string | Classes for the label row. |
Figma
Matches the Radio component. Figma Checked (Off, On) is the group's value. Label and Show label map to label and showLabel on each Radio.
See Figma for where to get the file and how its names map to code.