Forms
Radio group
Chooses exactly one option from a short list.
Installation
npx sinaui add radioCopy the src/lib/ui/radio/ folder and tokens.css. No dependencies.
Examples
Basic
<script lang="ts">
import * as Radio from '#lib/ui/radio/index.js';
let room = $state('baghdad');
</script>
<Radio.Group legend="Reading room" bind:value={room}>
<Radio.Item value="baghdad">Bayt al-Hikma, Baghdad</Radio.Item>
<Radio.Item value="cordoba">Library of Córdoba</Radio.Item>
<Radio.Item value="fez">Al-Qarawiyyin, Fez</Radio.Item>
</Radio.Group>With hints
Each hint is read out with its option. Disabled options stay visible so people know they exist.
<script lang="ts">
import * as Radio from '#lib/ui/radio/index.js';
let copy = $state('scribe');
</script>
<Radio.Group legend="How should we copy it?" bind:value={copy}>
<Radio.Item value="scribe" hint="Hand-copied on paper from the Samarkand mills."
>Scribe</Radio.Item
>
<Radio.Item value="illuminated" hint="With gold leaf and lapis. Takes a season.">
Illuminated
</Radio.Item>
<Radio.Item value="summary" hint="The key chapters only." disabled>Summary</Radio.Item>
</Radio.Group>Horizontal
For two or three short options. Arrow keys still move in reading order.
<script lang="ts">
import * as Radio from '#lib/ui/radio/index.js';
let script = $state('naskh');
</script>
<Radio.Group legend="Script" orientation="horizontal" bind:value={script}>
<Radio.Item value="kufic">Kufic</Radio.Item>
<Radio.Item value="naskh">Naskh</Radio.Item>
<Radio.Item value="thuluth">Thuluth</Radio.Item>
</Radio.Group>Hint and error
Both belong to the whole group and are read with its question.
<script lang="ts">
import * as Radio from '#lib/ui/radio/index.js';
let script = $state<string>();
</script>
<Radio.Group
legend="Script for the copy"
bind:value={script}
required
hint="The copyist can write in one script per manuscript."
error={script ? undefined : 'Choose a script for the copy.'}
>
<Radio.Item value="muhaqqaq">Muhaqqaq</Radio.Item>
<Radio.Item value="rayhani">Rayhani</Radio.Item>
<Radio.Item value="tawqi">Tawqi‘</Radio.Item>
</Radio.Group>Props
Radio.Group
| Prop | Type | Default |
|---|---|---|
legend | string (required) | |
value | string, bindable | |
name | string | a unique id |
orientation | 'vertical' | 'horizontal' | 'vertical' |
disabled | boolean | false |
required | boolean | false |
hint | string | |
error | string |
Radio.Item
| Prop | Type | Default |
|---|---|---|
value | string (required) | |
hint | string | |
disabled | boolean | false |
Accessibility
- A
<fieldset>with a<legend>: screen readers announce the question with each option. - Native radios: the group is one Tab stop, and arrow keys move and select.
- Each group gets a unique
nameby default, so two groups on a page never merge.
| Key | Action |
|---|---|
| Tab | Moves into the group at the selected option. |
| ↓ / →, ↑ / ← | Selects the next / previous option. |
| Space | Selects the focused option if none is selected. |