- Frames
- 0
- Active effects
- 0
- Renderer
- none
radio.ts
import "@shader-ui/core/styles.css";
import { watchForm } from "@shader-ui/core";
document.body.insertAdjacentHTML(
"beforeend",
`<form id="delivery">
<fieldset>
<legend>Delivery</legend>
<label><input type="radio" name="delivery" value="standard" required> Standard, free</label>
<label><input type="radio" name="delivery" value="express" required> Express, €9.90</label>
<label><input type="radio" name="delivery" value="store" required> In-store pickup</label>
</fieldset>
</form>`,
);
watchForm(document.querySelector<HTMLFormElement>("#delivery")!, { guide: true });Delivery.tsx
import { Form, Radio } from "@shader-ui/react";
export function Delivery() {
return (
<Form guide>
<fieldset>
<legend>Delivery</legend>
<label>
<Radio name="delivery" value="standard" required /> Standard, free
</label>
<label>
<Radio name="delivery" value="express" required /> Express, €9.90
</label>
<label>
<Radio name="delivery" value="store" required /> In-store pickup
</label>
</fieldset>
</Form>
);
}When to use it
- For a single choice among a few options visible at once: delivery, plan.
- Not for a long list (beyond about 7 options): a dropdown, coming soon. Not for an independent yes / no: use a checkbox.
Recommendations
- Put the options in a logical order (cheapest to most expensive): light follows the HTML order, so the path makes sense.
Accessibility
The library
- Native <input type="radio"> elements: arrow keys, single choice, label.
- checked changes at once: no delay for screen readers. The path is visual only; radios along the way never look checked.
- Path of 600 ms at most; beyond 3 changes per second, a simple fade.
- Filled dot with 3:1 contrast, click area of at least 24 px, native control in high contrast.
Integration
- The group in a <fieldset>, with a <legend> that holds the question, and the same name.
- An error text for a required group.
WCAG 2.2 criteria: Non-text Contrast · Three Flashes or Below Threshold · Target Size (Minimum) · Error Identification
Props
| Prop | Type | Purpose |
|---|---|---|
name | string | The group: light travels through the options between the old and new choice. |
required | boolean | Required group: green dot, green line under the legend on first choice. |
effects, onEffectEnd, ref | | Same as the input. |
Spec
The normative spec for this component: Formulaire
Availability and resources
- Status
- available · open source
- Packages
- @shader-ui/react (React, Next.js)
@shader-ui/core (TypeScript, plain HTML) - Source code
- choice.ts (core) · Choice.tsx (React)