Forms

RadioGroup

A set of radio buttons for selecting a single option from a list. Supports colors, sizes, horizontal and vertical layouts, item descriptions, and loading state.

Playground

Experiment with different props in real-time.

Basic Usage

Pass an array of items and bind to the selected value.

<script lang="ts">
  import { RadioGroup } from 'sv5ui';

  let plan = $state('standard');

  const plans = [
    { value: 'starter', label: 'Starter' },
    { value: 'standard', label: 'Standard' },
    { value: 'premium', label: 'Premium' }
  ];
</script>

<RadioGroup items={plans} bind:value={plan} />

With Descriptions

Add a description field to each item for additional context.

Delivered within 1-2 business days

Delivered within 3-5 business days

Delivered within 7-10 business days

<script lang="ts">
  import { RadioGroup } from 'sv5ui';

  let delivery = $state('standard');

  const options = [
    { value: 'express', label: 'Express', description: 'Delivered within 1-2 business days' },
    { value: 'standard', label: 'Standard', description: 'Delivered within 3-5 business days' },
    { value: 'economy', label: 'Economy', description: 'Delivered within 7-10 business days' }
  ];
</script>

<RadioGroup items={options} bind:value={delivery} />

Horizontal

Set orientation="horizontal" for an inline layout.

<RadioGroup items={plans} bind:value={plan} orientation="horizontal" />

Sizes

5 sizes from extra small to extra large.

XS

SM

MD

LG

XL

<RadioGroup items={plans} bind:value={plan} size="xs" />
<RadioGroup items={plans} bind:value={plan} size="sm" />
<RadioGroup items={plans} bind:value={plan} size="md" />
<RadioGroup items={plans} bind:value={plan} size="lg" />
<RadioGroup items={plans} bind:value={plan} size="xl" />

Colors

Semantic color schemes for the radio indicators.

Primary

Secondary

Success

Error

<RadioGroup items={plans} bind:value={plan} color="primary" />
<RadioGroup items={plans} bind:value={plan} color="secondary" />
<RadioGroup items={plans} bind:value={plan} color="success" />
<RadioGroup items={plans} bind:value={plan} color="error" />

With Legend

Use the legend prop to add an accessible fieldset legend.

Choose your plan
<RadioGroup
  items={plans}
  bind:value={plan}
  legend="Choose your plan"
  required
/>

Disabled Items

Set disabled on individual items to prevent selection.

<script lang="ts">
  import { RadioGroup } from 'sv5ui';

  let tier = $state('free');

  const tiers = [
    { value: 'free', label: 'Free' },
    { value: 'pro', label: 'Pro' },
    { value: 'enterprise', label: 'Enterprise', disabled: true }
  ];
</script>

<RadioGroup items={tiers} bind:value={tier} />

Loading

Show a skeleton loading state while data is being fetched.

<RadioGroup items={plans} bind:value={plan} loading />

UI Slots

Use the ui prop to override classes on specific internal elements.

SlotDescription
rootOutermost wrapper element
fieldsetFieldset element wrapping the group
legendLegend element for the fieldset
itemEach radio item row
containerWrapper around the radio indicator
baseThe radio circle element
indicatorThe inner dot indicator when selected
loadingIconLoading spinner icon
labelLabel text for each item
descriptionDescription text below each label
wrapperWrapper around the label and description

Snippets

Use snippets to customize legend, label, and description rendering.

SnippetArgsDescription
legendSlot{ legend }Custom legend rendering
labelSlot{ item }Custom label rendering for each item
descriptionSlot{ item }Custom description rendering for each item

Props

PropTypeDefault
valuestring''
onValueChange(value: string) => void-
itemsRadioGroupItem[][]
colorColor'primary'
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'
orientation'vertical' | 'horizontal''vertical'
legendstring-
loadingbooleanfalse
loadingIconstringicons.loading
disabledbooleanfalse
requiredbooleanfalse
loopbooleantrue
idstring-
namestring-
classstring-
uiRecord<Slot, Class>-

Item Props

Each object in the items array accepts these properties.

PropTypeDefault
valuestring-
labelstring-
descriptionstring-
disabledbooleanfalse