Skip to content
Navigation Core Stable

Sidebar

.md

A collapsible, grouped navigation rail with labelled sections, a current-item accent, and badges folded into each item's accessible name.

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { Sidebar } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import { Sidebar, SidebarGroup, SidebarItem } from "fancy-ui-svelte";

	let current = $state("dashboard");
</script>

<Sidebar>
	<SidebarGroup label="General">
		<SidebarItem
			sound
			href="#dashboard"
			current={current === "dashboard"}
			onclick={() => (current = "dashboard")}
		>
			Dashboard
		</SidebarItem>
		<SidebarItem
			sound
			href="#projects"
			current={current === "projects"}
			onclick={() => (current = "projects")}
		>
			Projects
		</SidebarItem>
		<SidebarItem
			sound
			href="#settings"
			current={current === "settings"}
			onclick={() => (current = "settings")}
		>
			Settings
		</SidebarItem>
	</SidebarGroup>
</Sidebar>

Examples

Basic Usage

With Badges

A count folded into an item's accessible name, and a second grouped section.

Collapsed

Icon-only rail — labels and badge meaning move to sr-only text, never removed.

An avatar and name row, above a separator, pinned to the bottom.

Props

PropTypeDefaultDescription
label string"Sidebar"Accessible name for the nav landmark.
collapsed booleanfalseWhether the sidebar is collapsed to an icon-only rail. Plain, not bindable — nothing inside the compound ever changes it itself.
class string-Additional CSS classes, merged onto the root.
ref HTMLElement | nullnullBindable reference to the root nav element.
SidebarGroup.label *string-The section heading, e.g. "General".
SidebarGroup.class string-Additional CSS classes, merged onto the group.
SidebarItem.href string-Renders an <a> when set; a <button type="button"> otherwise.
SidebarItem.current booleanfalseMarks this as the current item — aria-current="page" plus the accent left bar.
SidebarItem.badge string | number-A count or short flag, e.g. 4, rendered as a pill.
SidebarItem.badgeLabel string-What the badge means, folded into the accessible name. Defaults to just the badge value.
SidebarItem.disabled booleanfalseDisables both the click and keyboard-activation paths.
SidebarItem.onclick (event: MouseEvent) => void-Native click handler, for the button branch. Never called while disabled.
SidebarItem.class string-Additional CSS classes, merged onto the item.
SidebarItem.ref HTMLAnchorElement | HTMLButtonElement | nullnullBindable reference to the item's interactive element.
SidebarItem.sound booleanfalsePlays select when a sidebar item that is not already current is activated, once the user has enabled sound
SidebarSeparator.class string-Additional CSS classes, merged onto the hairline.
SidebarSeparator.ref HTMLHRElement | nullnullBindable reference to the <hr> element.
SidebarFooter.class string-Additional CSS classes, merged onto the footer row.
SidebarFooter.ref HTMLDivElement | nullnullBindable reference to the footer's root element.

Slots

SlotDescription
children SidebarGroup, SidebarSeparator and SidebarFooter.
SidebarGroup.children The SidebarItems in this section.
SidebarItem.icon A decorative glyph or icon, shown even while the sidebar is collapsed.
SidebarItem.children The item's label. Moves to sr-only text while collapsed — never removed.
SidebarFooter.avatar A decorative avatar, shown even while the sidebar is collapsed.
SidebarFooter.children The name / text next to the avatar. sr-only while collapsed.