Radio Group
Installation
npx @mielui/svelte add radio-groupyarn dlx @mielui/svelte add radio-groupbunx @mielui/svelte add radio-groupUsage
Bind value on Root and add one RadioGroup.Item per option. Each group owns its keyboard selection and generated item ids. Set name when the selected value should be submitted with a form. Descriptions are linked to their inputs, and keyboard focus appears on the visible radio.
<script lang="ts">
import * as RadioGroup from '@mielui/svelte/components/radio-group';
let plan = $state('pro');
</script>
<RadioGroup.Root bind:value={plan} name="plan" aria-label="Plan">
<RadioGroup.Item value="free" label="Free" />
<RadioGroup.Item value="pro" label="Pro" />
</RadioGroup.Root>Examples
With descriptions
Disabled
Change events
onValueChange reports each new choice without binding value. The group is named by a visible label through aria-labelledby.
No change yet
Events and naming
onValueChange on Root runs with the new value each time the choice changes. Name the group with a legend, an aria-label, or aria-labelledby pointing at the id of a visible label.
Item takes its text through label and description. Root renders the items you pass as its children. Resetting the form restores the initial value.
API reference
RadioGroup.Root
Manages a single selection.
valueBindablestringSelected value. Bindable.
namestringField name submitted with the form.
disabledbooleanPrevents interaction and dims the control.
Default
falseonValueChange((value: string) => void)Called with the new value when it changes.
aria-labelstringAccessible name when there is no visible label.
aria-labelledbystringId of the element that labels it.
childrenSnippet<[]>Content rendered inside.
classstringClasses added to the element.
RadioGroup.Item
Defines a radio option.
valueRequiredstringValue this option selects.
disabledbooleanPrevents interaction and dims the control.
labelstringVisible label linked to the control.
descriptionstringSupporting text under the label, announced with the control.
idstringId of the element.
class(string & (ClassValue | null))Classes added to the element.
childrenSnippet<[]>Content rendered inside.
pnpm dlx @mielui/svelte add radio-group