Radio Group
A set of options where only one can be selected.
Radio Group follows the Radio Group WAI-ARIA design pattern (the roving tabindex version).
import { component$, useStyles$ } from '@builder.io/qwik';
import { RadioGroup } from '@leve-ui/radio-group';
import styles from './default.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<RadioGroup.Root class="radio-group-default-root">
<RadioGroup.Label class="radio-group-default-label">Plan</RadioGroup.Label>
<RadioGroup.Item value="free" class="radio-group-default-item">
<RadioGroup.Indicator class="radio-group-default-indicator" />
Free
</RadioGroup.Item>
<RadioGroup.Item value="starter" class="radio-group-default-item">
<RadioGroup.Indicator class="radio-group-default-indicator" />
Starter
</RadioGroup.Item>
<RadioGroup.Item value="pro" class="radio-group-default-item">
<RadioGroup.Indicator class="radio-group-default-indicator" />
Pro
</RadioGroup.Item>
</RadioGroup.Root>
);
});.radio-group-default-root {
font-family: inherit;
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
.radio-group-default-label {
font-size: 14px;
font-weight: 600;
color: light-dark(#0f172a, #ffffff);
}
.radio-group-default-item {
display: inline-flex;
align-items: center;
gap: 10px;
padding: 0;
background: none;
border: none;
font: inherit;
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
text-align: left;
}
.radio-group-default-item:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
border-radius: 4px;
}
.radio-group-default-item:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.radio-group-default-indicator {
flex-shrink: 0;
width: 16px;
height: 16px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 9999px;
background: light-dark(#ffffff, #1b2045);
box-sizing: border-box;
}
/* A thick accent border draws the selected dot */
.radio-group-default-indicator[data-state="checked"] {
border: 5px solid #009dfd;
}Installation#
Install the individual package, or use @leve-ui/core to get every component at once:
pnpm add @leve-ui/radio-groupnpm install @leve-ui/radio-groupyarn add @leve-ui/radio-groupbun add @leve-ui/radio-grouppnpm add @leve-ui/corenpm install @leve-ui/coreyarn add @leve-ui/corebun add @leve-ui/coreAnatomy#
import { RadioGroup } from '@leve-ui/radio-group'; // or '@leve-ui/core'
<RadioGroup.Root>
<RadioGroup.Label />
<RadioGroup.Item>
<RadioGroup.Indicator />
</RadioGroup.Item>
<RadioGroup.HiddenInput />
</RadioGroup.Root>
| Part | Element | Description |
|---|---|---|
RadioGroup.Root | <div> | The group, with role="radiogroup". Holds the selected value. |
RadioGroup.Label | <span> | The label. Names the group. |
RadioGroup.Item | <button> | One option, with role="radio". |
RadioGroup.Indicator | <span> | Holds the dot or other icons. Always rendered. |
RadioGroup.HiddenInput | <input type="radio"> | Optional. Sends the selected value with a native <form>. |
Examples#
Controlled#
bind:value controls the selected value with a signal. The buttons outside the group change it, and setting it to null clears the selection.
Current value: banana
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { RadioGroup } from '@leve-ui/radio-group';
import styles from './controlled.css?inline';
export default component$(() => {
useStyles$(styles);
const selected = useSignal<string | null>('banana');
return (
<div class="radio-group-controlled-wrapper">
<RadioGroup.Root bind:value={selected} class="radio-group-controlled-root">
<RadioGroup.Label class="radio-group-controlled-label">Favorite fruit</RadioGroup.Label>
<RadioGroup.Item value="apple" class="radio-group-controlled-item">
<RadioGroup.Indicator class="radio-group-controlled-indicator" />
Apple
</RadioGroup.Item>
<RadioGroup.Item value="banana" class="radio-group-controlled-item">
<RadioGroup.Indicator class="radio-group-controlled-indicator" />
Banana
</RadioGroup.Item>
<RadioGroup.Item value="orange" class="radio-group-controlled-item">
<RadioGroup.Indicator class="radio-group-controlled-indicator" />
Orange
</RadioGroup.Item>
</RadioGroup.Root>
<div class="radio-group-controlled-controls">
<button
type="button"
class="radio-group-controlled-button"
onClick$={() => {
selected.value = 'apple';
}}
>
Select Apple
</button>
<button
type="button"
class="radio-group-controlled-button"
onClick$={() => {
selected.value = 'orange';
}}
>
Select Orange
</button>
<button
type="button"
class="radio-group-controlled-button"
onClick$={() => {
selected.value = null;
}}
>
Clear Selection
</button>
</div>
<p class="radio-group-controlled-value">Current value: {selected.value ?? '(none)'}</p>
</div>
);
});.radio-group-controlled-wrapper {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
font-family: inherit;
}
.radio-group-controlled-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
.radio-group-controlled-label {
font-size: 14px;
font-weight: 600;
color: light-dark(#0f172a, #ffffff);
}
.radio-group-controlled-item {
display: inline-flex;
align-items: center;
gap: 10px;
padding: 0;
background: none;
border: none;
font: inherit;
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
text-align: left;
}
.radio-group-controlled-item:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
border-radius: 4px;
}
.radio-group-controlled-item:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.radio-group-controlled-indicator {
flex-shrink: 0;
width: 16px;
height: 16px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 9999px;
background: light-dark(#ffffff, #1b2045);
box-sizing: border-box;
}
/* A thick accent border draws the selected dot */
.radio-group-controlled-indicator[data-state="checked"] {
border: 5px solid #009dfd;
}
.radio-group-controlled-controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.radio-group-controlled-button {
height: 32px;
padding: 0 12px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font: inherit;
font-size: 13px;
font-weight: 500;
cursor: pointer;
}
.radio-group-controlled-button:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.radio-group-controlled-button:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.radio-group-controlled-value {
margin: 0;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}Default Value#
defaultValue sets the initially selected value.
import { component$, useStyles$ } from '@builder.io/qwik';
import { RadioGroup } from '@leve-ui/radio-group';
import styles from './default-value.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<RadioGroup.Root defaultValue="starter" class="radio-group-default-value-root">
<RadioGroup.Label class="radio-group-default-value-label">Plan</RadioGroup.Label>
<RadioGroup.Item value="free" class="radio-group-default-value-item">
<RadioGroup.Indicator class="radio-group-default-value-indicator" />
Free
</RadioGroup.Item>
<RadioGroup.Item value="starter" class="radio-group-default-value-item">
<RadioGroup.Indicator class="radio-group-default-value-indicator" />
Starter
</RadioGroup.Item>
<RadioGroup.Item value="pro" class="radio-group-default-value-item">
<RadioGroup.Indicator class="radio-group-default-value-indicator" />
Pro
</RadioGroup.Item>
</RadioGroup.Root>
);
});.radio-group-default-value-root {
font-family: inherit;
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
.radio-group-default-value-label {
font-size: 14px;
font-weight: 600;
color: light-dark(#0f172a, #ffffff);
}
.radio-group-default-value-item {
display: inline-flex;
align-items: center;
gap: 10px;
padding: 0;
background: none;
border: none;
font: inherit;
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
text-align: left;
}
.radio-group-default-value-item:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
border-radius: 4px;
}
.radio-group-default-value-item:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.radio-group-default-value-indicator {
flex-shrink: 0;
width: 16px;
height: 16px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 9999px;
background: light-dark(#ffffff, #1b2045);
box-sizing: border-box;
}
/* A thick accent border draws the selected dot */
.radio-group-default-value-indicator[data-state="checked"] {
border: 5px solid #009dfd;
}Disabled#
disabled on the Root disables every item.
import { component$, useStyles$ } from '@builder.io/qwik';
import { RadioGroup } from '@leve-ui/radio-group';
import styles from './disabled.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<RadioGroup.Root disabled defaultValue="opt1" class="radio-group-disabled-root">
<RadioGroup.Label class="radio-group-disabled-label">Disabled group</RadioGroup.Label>
<RadioGroup.Item value="opt1" class="radio-group-disabled-item">
<RadioGroup.Indicator class="radio-group-disabled-indicator" />
Option 1
</RadioGroup.Item>
<RadioGroup.Item value="opt2" class="radio-group-disabled-item">
<RadioGroup.Indicator class="radio-group-disabled-indicator" />
Option 2
</RadioGroup.Item>
</RadioGroup.Root>
);
});.radio-group-disabled-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
font-family: inherit;
}
.radio-group-disabled-label {
font-size: 14px;
font-weight: 600;
color: light-dark(#0f172a, #ffffff);
}
.radio-group-disabled-item {
display: inline-flex;
align-items: center;
gap: 10px;
padding: 0;
background: none;
border: none;
font: inherit;
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
text-align: left;
}
.radio-group-disabled-item:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
border-radius: 4px;
}
.radio-group-disabled-item:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.radio-group-disabled-indicator {
flex-shrink: 0;
width: 16px;
height: 16px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 9999px;
background: light-dark(#ffffff, #1b2045);
box-sizing: border-box;
}
/* A thick accent border draws the selected dot */
.radio-group-disabled-indicator[data-state="checked"] {
border: 5px solid #009dfd;
}
.radio-group-disabled-label[data-disabled] {
opacity: 0.5;
}Disabled Item#
disabled on an Item disables only that option. Arrow keys skip it.
import { component$, useStyles$ } from '@builder.io/qwik';
import { RadioGroup } from '@leve-ui/radio-group';
import styles from './disabled-item.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<RadioGroup.Root class="radio-group-disabled-item-root">
<RadioGroup.Label class="radio-group-disabled-item-label">Shipping method</RadioGroup.Label>
<RadioGroup.Item value="standard" class="radio-group-disabled-item-item">
<RadioGroup.Indicator class="radio-group-disabled-item-indicator" />
Standard (3-5 days)
</RadioGroup.Item>
<RadioGroup.Item value="express" disabled class="radio-group-disabled-item-item">
<RadioGroup.Indicator class="radio-group-disabled-item-indicator" />
Express (Unavailable)
</RadioGroup.Item>
<RadioGroup.Item value="overnight" class="radio-group-disabled-item-item">
<RadioGroup.Indicator class="radio-group-disabled-item-indicator" />
Overnight
</RadioGroup.Item>
</RadioGroup.Root>
);
});.radio-group-disabled-item-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
font-family: inherit;
}
.radio-group-disabled-item-label {
font-size: 14px;
font-weight: 600;
color: light-dark(#0f172a, #ffffff);
}
.radio-group-disabled-item-item {
display: inline-flex;
align-items: center;
gap: 10px;
padding: 0;
background: none;
border: none;
font: inherit;
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
text-align: left;
}
.radio-group-disabled-item-item:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
border-radius: 4px;
}
.radio-group-disabled-item-item:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.radio-group-disabled-item-indicator {
flex-shrink: 0;
width: 16px;
height: 16px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 9999px;
background: light-dark(#ffffff, #1b2045);
box-sizing: border-box;
}
/* A thick accent border draws the selected dot */
.radio-group-disabled-item-indicator[data-state="checked"] {
border: 5px solid #009dfd;
}Horizontal#
orientation="horizontal" lays the group out in a row. It sets aria-orientation and data-orientation.
import { component$, useStyles$ } from '@builder.io/qwik';
import { RadioGroup } from '@leve-ui/radio-group';
import styles from './horizontal.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<RadioGroup.Root
orientation="horizontal"
defaultValue="card"
class="radio-group-horizontal-root"
>
<RadioGroup.Label class="radio-group-horizontal-label">Payment method</RadioGroup.Label>
<RadioGroup.Item value="card" class="radio-group-horizontal-item">
<RadioGroup.Indicator class="radio-group-horizontal-indicator" />
Card
</RadioGroup.Item>
<RadioGroup.Item value="paypal" class="radio-group-horizontal-item">
<RadioGroup.Indicator class="radio-group-horizontal-indicator" />
PayPal
</RadioGroup.Item>
<RadioGroup.Item value="bank" class="radio-group-horizontal-item">
<RadioGroup.Indicator class="radio-group-horizontal-indicator" />
Bank transfer
</RadioGroup.Item>
</RadioGroup.Root>
);
});.radio-group-horizontal-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
font-family: inherit;
}
.radio-group-horizontal-label {
font-size: 14px;
font-weight: 600;
color: light-dark(#0f172a, #ffffff);
}
.radio-group-horizontal-item {
display: inline-flex;
align-items: center;
gap: 10px;
padding: 0;
background: none;
border: none;
font: inherit;
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
text-align: left;
}
.radio-group-horizontal-item:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
border-radius: 4px;
}
.radio-group-horizontal-item:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.radio-group-horizontal-indicator {
flex-shrink: 0;
width: 16px;
height: 16px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 9999px;
background: light-dark(#ffffff, #1b2045);
box-sizing: border-box;
}
/* A thick accent border draws the selected dot */
.radio-group-horizontal-indicator[data-state="checked"] {
border: 5px solid #009dfd;
}
/* Items sit in a row; the label takes the full first line */
.radio-group-horizontal-root[data-orientation="horizontal"] {
flex-direction: row;
flex-wrap: wrap;
column-gap: 20px;
}
.radio-group-horizontal-label {
flex-basis: 100%;
}With Field#
Inside a Field, the group uses the Field's IDs, and reads its invalid, disabled and required states. Field.Description and Field.ErrorMessage are linked with aria-describedby. Name the group with RadioGroup.Label, not Field.Label: a <label> cannot name a group.
import { component$, useStyles$ } from '@builder.io/qwik';
import { Field } from '@leve-ui/field';
import { RadioGroup } from '@leve-ui/radio-group';
import styles from './with-field.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<Field.Root hasDescription required class="radio-group-with-field-field">
{/* RadioGroup.Label names the group; a <label> cannot */}
<RadioGroup.Root defaultValue="standard" class="radio-group-with-field-root">
<RadioGroup.Label class="radio-group-with-field-label">Shipping</RadioGroup.Label>
<RadioGroup.Item value="standard" class="radio-group-with-field-item">
<RadioGroup.Indicator class="radio-group-with-field-indicator" />
Standard
</RadioGroup.Item>
<RadioGroup.Item value="express" class="radio-group-with-field-item">
<RadioGroup.Indicator class="radio-group-with-field-indicator" />
Express
</RadioGroup.Item>
</RadioGroup.Root>
<Field.Description class="radio-group-with-field-description">
Express arrives in one business day.
</Field.Description>
</Field.Root>
);
});.radio-group-with-field-field {
display: flex;
flex-direction: column;
gap: 8px;
font-family: inherit;
}
.radio-group-with-field-root {
font-family: inherit;
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
.radio-group-with-field-label {
font-size: 14px;
font-weight: 600;
color: light-dark(#0f172a, #ffffff);
}
.radio-group-with-field-item {
display: inline-flex;
align-items: center;
gap: 10px;
padding: 0;
background: none;
border: none;
font: inherit;
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
text-align: left;
}
.radio-group-with-field-item:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
border-radius: 4px;
}
.radio-group-with-field-item:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.radio-group-with-field-indicator {
flex-shrink: 0;
width: 16px;
height: 16px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 9999px;
background: light-dark(#ffffff, #1b2045);
box-sizing: border-box;
}
/* A thick accent border draws the selected dot */
.radio-group-with-field-indicator[data-state="checked"] {
border: 5px solid #009dfd;
}
.radio-group-with-field-description {
margin: 0;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}With Form#
Add RadioGroup.HiddenInput with name to submit the selected value with a native <form>.
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { RadioGroup } from '@leve-ui/radio-group';
import styles from './with-form.css?inline';
export default component$(() => {
useStyles$(styles);
const submittedValue = useSignal<string | null>(null);
return (
<div class="radio-group-with-form-wrapper">
<form
class="radio-group-with-form-form"
preventdefault:submit
onSubmit$={(event) => {
const form = event.target as HTMLFormElement;
const formData = new FormData(form);
submittedValue.value = (formData.get('subscription') as string) || '(none)';
}}
>
<RadioGroup.Root defaultValue="monthly" class="radio-group-with-form-root">
<RadioGroup.Label class="radio-group-with-form-label">
Subscription billing
</RadioGroup.Label>
<RadioGroup.Item value="monthly" class="radio-group-with-form-item">
<RadioGroup.Indicator class="radio-group-with-form-indicator" />
Monthly billing ($10/mo)
</RadioGroup.Item>
<RadioGroup.Item value="yearly" class="radio-group-with-form-item">
<RadioGroup.Indicator class="radio-group-with-form-indicator" />
Yearly billing ($100/yr)
</RadioGroup.Item>
<RadioGroup.HiddenInput name="subscription" />
</RadioGroup.Root>
<button type="submit" class="radio-group-with-form-form-button">
Submit
</button>
</form>
{submittedValue.value !== null && (
<p class="radio-group-with-form-submitted" data-testid="submitted-value">
Submitted: {submittedValue.value}
</p>
)}
</div>
);
});.radio-group-with-form-wrapper {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
font-family: inherit;
}
.radio-group-with-form-form {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
.radio-group-with-form-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
.radio-group-with-form-label {
font-size: 14px;
font-weight: 600;
color: light-dark(#0f172a, #ffffff);
}
.radio-group-with-form-item {
display: inline-flex;
align-items: center;
gap: 10px;
padding: 0;
background: none;
border: none;
font: inherit;
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
text-align: left;
}
.radio-group-with-form-item:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
border-radius: 4px;
}
.radio-group-with-form-item:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.radio-group-with-form-indicator {
flex-shrink: 0;
width: 16px;
height: 16px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 9999px;
background: light-dark(#ffffff, #1b2045);
box-sizing: border-box;
}
/* A thick accent border draws the selected dot */
.radio-group-with-form-indicator[data-state="checked"] {
border: 5px solid #009dfd;
}
.radio-group-with-form-form-button {
height: 32px;
padding: 0 12px;
border: none;
border-radius: 6px;
background: #009dfd;
color: #ffffff;
font: inherit;
font-size: 13px;
font-weight: 500;
cursor: pointer;
}
.radio-group-with-form-form-button:hover {
background: #006ce9;
}
.radio-group-with-form-form-button:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.radio-group-with-form-submitted {
margin: 0;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}API Reference#
Root#
| Prop | Default | Type |
|---|---|---|
| ids | – | { label?: string; root?: string } Overrides the element IDs of the parts. Inside a Field, the Field's IDs are used instead. |
| defaultValue | null | string | null The value selected initially (uncontrolled). |
| bind:value | – | Signal<string | null> A signal with the selected value (controlled). |
| onValueChange$ | – | QRL<(value: string) => void> Called when the user selects a value. |
| orientation | 'vertical' | 'horizontal' | 'vertical' The orientation of the group. |
| loop | true | boolean Whether arrow keys wrap from the last item to the first and vice versa. |
| disabled | false | boolean Disables all radio buttons. |
| required | false | boolean Marks the group as required. |
Also accepts all <div> attributes.
| Data attribute | Value |
|---|---|
data-leve-radio-group | Always present |
data-orientation | "vertical" | "horizontal" |
data-disabled | Present when disabled |
data-invalid | Present when the surrounding Field is invalid |
The selected value is uncontrolled with defaultValue, or controlled with bind:value. onValueChange$ is called when the user selects a value. orientation only changes aria-orientation and data-orientation: all four arrow keys move the selection in both orientations.
Label#
No props of its own. Accepts all <span> attributes.
| Data attribute | Value |
|---|---|
data-leve-radio-group-label | Always present |
data-disabled | Present when the group is disabled |
The Label's id comes from the Root. To change it, pass ids={{ label: '...' }} to the Root (an id on the Label is also used, but then pass the same ID to the Root's aria-labelledby). Inside a Field, the Field's label ID is used.
Item#
| Prop | Default | Type |
|---|---|---|
| value (required) | – | string The value of this radio button. |
| disabled | false | boolean Disables this radio button. |
Also accepts all <button> attributes.
| Data attribute | Value |
|---|---|
data-leve-radio-group-item | Always present |
data-state | "checked" | "unchecked" |
data-disabled | Present when the item or the group is disabled |
data-orientation | "vertical" | "horizontal" |
Indicator#
No props of its own. Accepts all <span> attributes.
| Data attribute | Value |
|---|---|
data-leve-radio-group-indicator | Always present |
data-state | "checked" | "unchecked" |
data-disabled | Present when the item or the group is disabled |
The indicator is always rendered. Show or hide its contents with CSS, for example [data-leve-radio-group-indicator][data-state="checked"].
HiddenInput#
| Prop | Default | Type |
|---|---|---|
| form | – | string The |
Also accepts all <input> attributes.
| Data attribute | Value |
|---|---|
data-leve-radio-group-hidden-input | Always present |
data-state | "checked" when a value is selected, otherwise "unchecked" |
data-disabled | Present when the group is disabled |
The hidden input holds the selected value and follows the required and disabled states of the Root, so native form submission and required validation work (ADR 0026). It is positioned absolutely with an inline style, so give RadioGroup.Root position: relative.
Accessibility#
Complies with the Radio Group WAI-ARIA design pattern.
- Name the group with
RadioGroup.Label, oraria-label/aria-labelledbyonRadioGroup.Root. RadioGroup.Rootrendersrole="radiogroup",aria-orientation, andaria-required/aria-disabledwhen required or disabled. Inside a Field, it also rendersaria-describedbyforField.Description/Field.ErrorMessageandaria-invalid="true"while the Field is invalid.- Each
RadioGroup.Itemis a<button type="button">withrole="radio"andaria-checked. Its text content is its accessible name. Disabled items use the nativedisabledattribute, so they are not focusable. - Only one item is in the tab sequence: the selected item, or the first enabled item when nothing is selected.
RadioGroup.IndicatorandRadioGroup.HiddenInputare hidden from assistive technologies witharia-hidden="true".
Keyboard Interactions#
| Key | Description |
|---|---|
Tab | Moves focus into the group (to the selected item, or the first enabled item), or out of the group. |
Space | Selects the focused item. Enter does nothing. |
ArrowDown / ArrowRight | Moves focus to the next enabled item and selects it. Wraps to the first item when loop is true. |
ArrowUp / ArrowLeft | Moves focus to the previous enabled item and selects it. Wraps to the last item when loop is true. |
Home | Moves focus to the first enabled item and selects it. |
End | Moves focus to the last enabled item and selects it. |