Radio
A single radio button on a native <input type="radio">, grouped by name —
for hand-laid-out radios. For a managed set, use
Radio Group.
Import
Section titled “Import”<script> import Radio from "@invisible-ui/svelte/Radio.svelte";</script><script setup> import { Radio } from "@invisible-ui/vue";</script>import { Radio } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-radio></ds-radio>In Elements, the children are the label. The checked property reads the live
state, and choosing a radio sends a bubbling change event with
detail.value:
<fieldset> <legend>Plan</legend> <ds-radio name="plan" value="free" checked>Free</ds-radio> <ds-radio name="plan" value="pro">Pro</ds-radio></fieldset>| Prop | Type | Default | Description |
|---|---|---|---|
value * | string | — | This radio's value. |
name * | string | — | Group name (shared across radios). |
checked | boolean | false | Whether this radio is selected. |
disabled | boolean | false | Disable this radio. |
label | string | undefined | undefined | Visible label (or pass it as children). |
onChange | ((value: string) => void) | undefined | undefined | Called when this radio is chosen. |
| Prop | Type | Default | Description |
|---|---|---|---|
value * | string | — | The value submitted / reported when this radio is chosen. |
name * | string | — | Group name; radios sharing a name are mutually exclusive. |
checked | boolean | false | Whether this radio is selected. |
disabled | boolean | false | |
label | string | undefined | Label text, used when the default slot is empty. |
onChange | (value: string) => void | undefined | Called with this radio's value when it becomes selected. |
Slots: default.
| Prop | Type | Default | Description |
|---|---|---|---|
value * | string | — | The value submitted / reported when this radio is chosen. |
name * | string | — | Group name; radios sharing a name are mutually exclusive. |
checked | boolean | false | Whether this radio is selected. |
disabled | boolean | false | |
label | string | — | Label text, used when no children is given. |
onChange | (value: string) => void | — | Called with this radio's value when it becomes selected. |
children | ReactNode | — | Rich label content, in place of label. |
| Attribute | Reactive | Description |
|---|---|---|
value * | yes | |
name * | yes | |
checked | yes | |
disabled | yes | |
label | yes |
Reactive attributes re-render the element when they change after the first render.
Properties: checked.
Emits: bubbling change CustomEvent with detail.value when the radio is chosen.
Accessibility
Section titled “Accessibility”- A native
<input type="radio">, so grouping and keyboard behaviour are the platform’s.
Example
Section titled “Example”<Radio name="plan" value="pro" label="Pro" checked />In React, checked sets the radio’s state and onChange reports its value
when the user chooses it. The radios of one name share the choice through
the browser:
<Radio name="plan" value="free" label="Free" checked={plan === "free"} onChange={setPlan} /><Radio name="plan" value="pro" label="Pro" checked={plan === "pro"} onChange={setPlan} />Themeable via --ds-radio-*.