Skip to content
iv-ui v0.3.0

ToggleGroup

since 0.2.0

A row of toggles with single or multiple selection.

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

Single

One pressed toggle; choosing another releases the first.

view: list

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

	let view = $state('list');
</script>

<div class="stack">
	<ToggleGroup label="View" mode="single" items={['list', 'grid', 'table']} bind:value={view} />
	<p class="readout">view: {view}</p>
</div>

<style>
	.stack {
		display: flex;
		flex-direction: column;
		align-items: start;
		gap: var(--iv_spacing-sm);
	}

	.readout {
		margin: 0;
		font-family: var(--iv_font-mono);
		font-size: var(--iv_text-sm);
		color: var(--iv_foreground-dim);
	}
</style>
  • mode="single" behaves like a segmented control; "none" only emits clicks.
  • Items may be strings or { value, label, icon, disabled }.
  • Bind value; it is a string for single mode and an array for multiple.

Multiple

Several toggles can stay pressed at once.

shown: status, owner

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

	let columns = $state<string[]>(['status', 'owner']);
</script>

<div class="stack">
	<ToggleGroup
		label="Columns"
		mode="multiple"
		items={['status', 'owner', 'updated', 'branch']}
		bind:value={columns}
	/>
	<p class="readout">shown: {columns.join(', ') || '—'}</p>
</div>

<style>
	.stack {
		display: flex;
		flex-direction: column;
		align-items: start;
		gap: var(--iv_spacing-sm);
	}

	.readout {
		margin: 0;
		font-family: var(--iv_font-mono);
		font-size: var(--iv_text-sm);
		color: var(--iv_foreground-dim);
	}
</style>

Icons

Items with icons keep their labels for wide layouts.

Source· svelte Show Hide
<script lang="ts">
	import { IconLayoutGrid, IconList, IconTable } from '@tabler/icons-svelte';
	import { ToggleGroup } from '@elluzion/iv-ui';

	let view = $state('grid');

	const items = [
		{ value: 'list', label: 'List', icon: IconList },
		{ value: 'grid', label: 'Grid', icon: IconLayoutGrid },
		{ value: 'table', label: 'Table', icon: IconTable }
	];
</script>

<ToggleGroup label="View" mode="single" {items} bind:value={view} />
import { ToggleGroup } from '@elluzion/iv-ui';

Props

7 props · 1 events · 1 snippets
PropTypeDefaultDescription
items ToggleGroupItem[][]Toggles to render. Items may be strings or { value, label, icon, disabled }.
mode ToggleGroupMode'none'Selection behaviour: one value, many values, or none.
value bindablestring | string[]mode === 'multiple' ? [] : ''Selected value(s). Bind with bind:value.
label string''Accessible name for the group.
size 'sm' | 'md' | 'lg''md'Control size.
orientation 'horizontal' | 'vertical''horizontal'Stacking direction.
disabled booleanfalseDisables interaction and applies the disabled treatment.

All native <div> attributes are forwarded.

Events

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

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

Snippets

SnippetTypeDescription
childrenSnippetContent rendered inside the component.

Types

ToggleGroupMode

Selection behaviour of a toggle group.

type ToggleGroupMode = 'single' | 'multiple' | 'none';
ToggleGroupItem

A toggle description or a plain string label.

type ToggleGroupItem =
	| string
	| {
			value: string;
			label?: string;
			icon?: Icon;
			disabled?: boolean;
	  };
KeysAction
TabMoves focus through the toggles.
Space / EnterToggles the focused item.
  • The container uses role="group" and is named by label.
  • Each option is a button with aria-pressed.
  • Selection is never changed by arrow keys, so every item stays reachable with Tab.
Class hooks
.iv-checked.iv-disabled.iv-lg.iv-sm.iv-toggle.iv-toggle-group.iv-vertical
iv-ui
↑ ↓ navigate ↵ open esc close minisearch · 482 records