Forms

Segmented control

Switches between a few mutually exclusive views or options.

Installation

npx sinaui add segmented

Examples

Basic

Click and the thumb glides; arrow keys snap it.

Text shown

Showing: Side by side

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

	let view = $state('both');
	const views = [
		{ value: 'arabic', label: 'Arabic' },
		{ value: 'latin', label: 'Latin' },
		{ value: 'both', label: 'Side by side' }
	];
</script>

<Segmented label="Text shown" options={views} bind:value={view} />
<p class="note">Showing: {views.find((v) => v.value === view)?.label}</p>

<style>
	.note {
		margin: 0;
		color: var(--ui-muted);
	}
</style>

Label for screen readers only

Loans in the last
<script lang="ts">
	import Segmented from '#lib/ui/Segmented.svelte';

	let period = $state('month');
</script>

<!-- When context makes the question obvious, keep the label for screen readers only. -->
<Segmented
	label="Loans in the last"
	hideLabel
	options={[
		{ value: 'week', label: 'Week' },
		{ value: 'month', label: 'Month' },
		{ value: 'year', label: 'Year' }
	]}
	bind:value={period}
/>

Props

PropTypeDefault
labelstring (required)
hideLabelbooleanfalse
options{ value, label }[]
valuestring, bindable
namestringa unique id
disabledbooleanfalse

Accessibility

  • Native radios in a <fieldset>: one Tab stop, arrow keys and forms need no JavaScript.
  • Correct before hydration: the chosen segment is raised in the server HTML.
  • For two to five short options. More than that: a Select.
KeyAction
TabMoves into the control at the chosen option.
← / →Chooses the previous / next option.
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