skip section navigation

Switcher

Switcher arranges buttons and moves a highlight behind the one with loaf-active. it doesn’t own selection, routing or tab panels. keep those decisions in the buttons you supply.

  • I'm Luffy! The Man Who Will Become the Pirate King!
  • The Great Swordsman Appears! Pirate Hunter, Roronoa Zoro

usage

svelte
<script>
	import { Switcher } from '@ciabi/loafkit-ui';
	let mode = $state('comfortable');
</script>

<Switcher aria-label="Reading density">
	<button type="button" class:loaf-active={mode === 'comfortable'}
		aria-pressed={mode === 'comfortable'} onclick={() => mode = 'comfortable'}>Comfortable</button>
	<button type="button" class:loaf-active={mode === 'compact'}
		aria-pressed={mode === 'compact'} onclick={() => mode = 'compact'}>Compact</button>
</Switcher>
<ul>
	<li><strong>the balcony garden</strong>{#if mode === 'comfortable'}<p>herbs that do well in a small space.</p>{/if}</li>
	<li><strong>a quieter weekend</strong>{#if mode === 'comfortable'}<p>one good article, without the backlog.</p>{/if}</li>
</ul>

the buttons use aria-pressed because they choose a display mode. this isn’t a tab interface, so it doesn’t pretend to provide tab keyboard behavior.

composition

  • Switcher
    • button (app-owned state and handler)

props and layout

use description for shared help beneath the group. its generated ID joins any aria-describedby you supply.

API reference

Switcher

Component
children

buttons whose handlers own selection; mark the selected button loaf-active.

fullWidth
Default: false

fills the available width.

description
Default: ''

shared help text, automatically included in the group description.

id

ID on the inner switcher.

aria-label

an explicit accessible name.

aria-labelledby

IDs of elements that provide the accessible name.

aria-describedby

IDs of supporting descriptions.

invalid
Default: false

adds the visual invalid data attribute; child controls own validity.

class
Default: ''

extra classes on the inner switcher.

style

inline styles on the inner switcher.