Skip to content
iv-ui v0.3.0

RadioGroup

since 0.1.0

A set of mutually exclusive options with one selected value.

import { RadioGroup } from '@elluzion/iv-ui';

Basic

A vertical list with one selected value.

Plan

selected: pro

Source· svelte Show Hide
<script lang="ts">
	import { RadioGroup } from '@elluzion/iv-ui';

	let plan = $state('pro');
</script>

<div class="field-row">
	<RadioGroup
		label="Plan"
		items={[
			{ value: 'free', label: 'Free' },
			{ value: 'pro', label: 'Pro' },
			{ value: 'team', label: 'Team' }
		]}
		bind:value={plan}
	/>
	<p class="readout">selected: {plan}</p>
</div>

<style>
	.field-row {
		display: flex;
		flex-direction: column;
		gap: var(--iv_spacing-md);
		width: 100%;
		max-width: 320px;
	}

	.readout {
		margin: 0;
		font-family: var(--iv_font-mono);
		font-size: var(--iv_text-sm);
		color: var(--iv_foreground-dim);
	}
</style>
  • items accepts strings or { value, label, disabled }.
  • Bind value; onchange fires with { value } after a selection changes.
  • Use orientation="horizontal" for compact choice rows.

Horizontal

The same group laid out as a row.

Digest cadence
Source· svelte Show Hide
<script lang="ts">
	import { RadioGroup } from '@elluzion/iv-ui';

	let cadence = $state('daily');
</script>

<div class="field-row">
	<RadioGroup
		label="Digest cadence"
		orientation="horizontal"
		items={['hourly', 'daily', 'weekly']}
		bind:value={cadence}
	/>
</div>

<style>
	.field-row {
		width: 100%;
		max-width: 420px;
	}
</style>

Disabled

A disabled option and a fully disabled group.

Plan
Region
Source· svelte Show Hide
<script lang="ts">
	import { RadioGroup } from '@elluzion/iv-ui';

	let plan = $state('pro');
</script>

<div class="field-row">
	<RadioGroup
		label="Plan"
		items={[
			{ value: 'free', label: 'Free' },
			{ value: 'pro', label: 'Pro' },
			{ value: 'enterprise', label: 'Enterprise — sales only', disabled: true }
		]}
		bind:value={plan}
	/>
	<RadioGroup label="Region" items={['eu-west', 'us-east']} value="eu-west" disabled />
</div>

<style>
	.field-row {
		display: flex;
		flex-direction: column;
		gap: var(--iv_spacing-xl);
		width: 100%;
		max-width: 320px;
	}
</style>
import { RadioGroup } from '@elluzion/iv-ui';

Props

7 props · 1 events · 0 snippets
PropTypeDefaultDescription
items required RadioItem[][]Radio options. Strings are used as both value and label.
value bindablestring''Selected value. Bind with bind:value.
label string''Visible label for the control.
name string''Shared name for the native radio inputs.
size 'sm' | 'md''md'Control size.
orientation 'horizontal' | 'vertical''vertical'Layout direction.
disabled booleanfalseDisables interaction and applies the disabled treatment.

Events

EventHandler typeDescription
onchange(e: CustomEvent<{ value: string }>) => voidCalled with { value } after the selection changes.

The legacy on:name form is accepted for every event.

Types

RadioItem

A radio value or a labelled radio option.

type RadioItem = string | { value: string; label?: string; disabled?: boolean };
KeysAction
TabMoves focus into the group.
Arrow keysMove between radios and select the focused one.
SpaceSelects the focused radio.
  • The group is labelled by label through aria-labelledby.
  • Each option is a native radio input inside a <label>.
  • Only the selected radio is in the tab order, matching native behaviour.
Class hooks
.iv-checked.iv-circle.iv-disabled.iv-dot.iv-group-label.iv-horizontal.iv-item.iv-items.iv-label.iv-md.iv-native.iv-root.iv-sm
iv-ui
↑ ↓ navigate ↵ open esc close minisearch · 482 records