Forms Core Stable

RadioGroup

A set of mutually exclusive options, built on real input type=radio elements sharing one name so the browser gives the roving tab stop and keyboard navigation for free.

Preview

Installation

pnpm add fancy-ui-svelte
import { RadioGroup } from 'fancy-ui-svelte'

Usage

svelte
<script lang="ts">
  import { RadioGroup } from 'fancy-ui-svelte';
</script>

<RadioGroup />

Examples

Basic Usage

Three options, one selected by default.

Horizontal

The list laid out along a row instead of a column.

Disabled Items

One option unavailable — skipped by the keyboard and never selectable.

With FormField

Wrapped in FormField — required and the error message driven by context.

Props

PropTypeDefaultDescription
value string""The selected value, bindable — "" means nothing is selected.
onValueChange (value: string) => void-Called with the new value whenever the selection changes.
name string-Shared name for the native radios. Generated per instance when omitted, so two groups on the same page never fight over each other's selection.
disabled booleanfalseDisables every item in the group.
required booleanfalseMarks the group required for native form validation.
invalid booleanfalseMarks the group invalid — sets aria-invalid.
orientation "horizontal" | "vertical""vertical"The list's stacking axis.
label string-Accessible name, standalone. Inside a FormField that rendered its own label, its labelId wins instead; a FormField with no label of its own falls back to this.
class string-Additional CSS classes, merged onto the root.
ref HTMLDivElement | nullnullBindable reference to the root element.
RadioGroupItem.value *string-This item's value — what the group's value becomes when it is picked.
RadioGroupItem.disabled booleanfalseDisables just this item, independent of the group's own disabled.
RadioGroupItem.label string-Visible label text. Also the fallback content, and the fallback name.
RadioGroupItem.class string-Additional CSS classes, merged onto the wrapping label.
RadioGroupItem.ref HTMLInputElement | nullnullBindable reference to the item's native input.
sound booleanfalsePlays a select cue when the selection actually changes, once the user has enabled sound

Slots

SlotDescription
childrenThe RadioGroup's content — the RadioGroupItems.
RadioGroupItem.childrenCustom content rendered in place of the item's label.