Forms

Toggle group

Turns several options on and off, like bold, italic and underline.

Installation

npx sinaui add toggle-group

Examples

Icons

Icon buttons are named by their tooltip, shown on hover or keyboard focus.

Medicine is the science by which we learn the states of the human body.

<script lang="ts">
	import {
		TextBoldIcon,
		TextItalicIcon,
		TextStrikethroughIcon,
		TextUnderlineIcon
	} from '@hugeicons/core-free-icons';
	import ToggleGroup from '#lib/ui/ToggleGroup.svelte';

	let style = $state(['bold']);
</script>

<div class="stack">
	<ToggleGroup
		label="Text style"
		bind:value={style}
		items={[
			{ value: 'bold', label: 'Bold', icon: TextBoldIcon },
			{ value: 'italic', label: 'Italic', icon: TextItalicIcon },
			{ value: 'underline', label: 'Underline', icon: TextUnderlineIcon },
			{ value: 'strike', label: 'Strikethrough', icon: TextStrikethroughIcon }
		]}
	/>
	<p
		class:bold={style.includes('bold')}
		class:italic={style.includes('italic')}
		class:underline={style.includes('underline')}
		class:strike={style.includes('strike')}
	>
		Medicine is the science by which we learn the states of the human body.
	</p>
</div>

<style>
	.stack {
		display: grid;
		gap: 1rem;
	}
	p {
		margin: 0;
	}
	.bold {
		font-weight: 600;
	}
	.italic {
		font-style: italic;
	}
	.underline {
		text-decoration: underline;
	}
	.strike {
		text-decoration: line-through;
	}
	.underline.strike {
		text-decoration: underline line-through;
	}
</style>

Text labels

A disabled button is skipped by the arrow keys.

Showing: arabic, latin

<script lang="ts">
	import ToggleGroup from '#lib/ui/ToggleGroup.svelte';

	let columns = $state(['arabic', 'latin']);
</script>

<div class="stack">
	<ToggleGroup
		label="Columns to show"
		size="sm"
		bind:value={columns}
		items={[
			{ value: 'arabic', label: 'Arabic' },
			{ value: 'latin', label: 'Latin' },
			{ value: 'commentary', label: 'Commentary' },
			{ value: 'facsimile', label: 'Facsimile', disabled: true }
		]}
	/>
	<p>Showing: {columns.length ? columns.join(', ') : 'nothing'}</p>
</div>

<style>
	.stack {
		display: grid;
		gap: 1rem;
		justify-items: start;
	}
	p {
		margin: 0;
		color: var(--ui-muted);
		font-size: 0.875rem;
	}
</style>

Props

PropTypeDefault
labelstring (required)
items{ value, label, icon?, disabled? }[]
valuestring[], bindable[]
size'sm' | 'md''md'

Accessibility

  • A toolbar with one Tab stop; each button says whether it's on (aria-pressed).
  • Buttons are 44px on touch screens.
KeyAction
TabMoves into the group, to the last button used.
← →Previous / next button (mirrored right to left), wrapping round.
Home EndFirst / last button.
Space EnterTurn the button on or off.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme