RadioGroup
Data inputA set of radio buttons with bind:value: <RadioGroup.Root> holds one RadioGroup.Item per option. Tab enters the group, arrow keys move and select. Put each item in a Field orientation="horizontal" with a Field.Label, and the group in a Field.Set with a Field.Legend that names it.
import { RadioGroup } from '@limerdev/zest'; Use for
Choosing exactly one of a few options (up to about six) that should all be visible.
Don't
Many options, or options that don't fit on screen: use
Select. Independent on/off choices: use Checkbox. A group without a Field.Legend (or aria-label).Examples
Basic
One Field per option; the Field.Legend names the group. Arrow keys move and select.
<script lang="ts">
import { Field, RadioGroup } from '@limerdev/zest';
let billing = $state('monthly');
</script>
<Field.Set>
<Field.Legend variant="label">Billing</Field.Legend>
<RadioGroup.Root bind:value={billing} name="billing">
<Field.Root orientation="horizontal" class="w-auto">
<RadioGroup.Item value="monthly" />
<Field.Label>Monthly</Field.Label>
</Field.Root>
<Field.Root orientation="horizontal" class="w-auto">
<RadioGroup.Item value="yearly" />
<Field.Label>Yearly</Field.Label>
</Field.Root>
</RadioGroup.Root>
</Field.Set> With descriptions
Field.Content puts a description under each option's label.
<script lang="ts">
import { Field, RadioGroup } from '@limerdev/zest';
type Plan = { value: string; label: string; description: string };
const plans: Plan[] = [
{ value: 'hourly', label: 'Hourly', description: 'Bill every logged hour.' },
{ value: 'fixed', label: 'Fixed price', description: 'One price for the project.' },
{ value: 'retainer', label: 'Retainer', description: 'A monthly amount of hours.' }
];
let plan = $state('hourly');
</script>
<Field.Set class="max-w-sm">
<Field.Legend variant="label">Pricing</Field.Legend>
<RadioGroup.Root bind:value={plan}>
{#each plans as option (option.value)}
<Field.Root orientation="horizontal">
<RadioGroup.Item value={option.value} />
<Field.Content>
<Field.Label>{option.label}</Field.Label>
<Field.Description>{option.description}</Field.Description>
</Field.Content>
</Field.Root>
{/each}
</RadioGroup.Root>
</Field.Set> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
RadioGroup.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| autocomplete | FullAutoFill | null | "off" | The autocomplete attribute to forward to the hidden input element. Browsers can otherwise autofill the hidden input with values that don't match any of the radio items. |
| disabled | boolean | false | Whether the radio group is disabled. |
| loop | boolean | true | Whether to loop around the radio items when navigating with the keyboard. |
| name | string | undefined | The name to apply to the radio group's input element for form submission. If not provided, a hidden input will not be rendered and the radio group will not be part of a form. |
| onValueChange | OnChangeFn<string> | โ | The callback to call when the selected radio item changes. |
| orientation | "horizontal" | "vertical" | "vertical" | The orientation of the radio group. Used to determine how keyboard navigation should work. |
| readonly | boolean | false | Whether the radio group is readonly. When readonly, users can focus and navigate through items but cannot change the value. |
| required | boolean | โ | Whether the radio group is required for form submission. If true, ensure you provide a name prop so the hidden input is rendered. |
| value bindable | string | '' | The value of the selected radio item. |
RadioGroup.Item
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | null | false | true | false | Whether the radio item is disabled. |
| value required | string | โ | The value of the radio item. |