Skip to the content
human-kit design

Sidebar

The app's column of navigation, with a head, the links and a foot, folding to a rail of icons.

Installation

pnpm dlx @human-kit/design add sidebar
npx @human-kit/design add sidebar
yarn dlx @human-kit/design add sidebar
bunx @human-kit/design add sidebar

The command copies the files to src/lib/components/ui/sidebar. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as NavList from '$lib/components/ui/nav-list';
	import * as Sidebar from '$lib/components/ui/sidebar';
	import Inbox from '@lucide/svelte/icons/inbox';

	let collapsed = $state(false);
</script>

<Sidebar.Root bind:collapsed>
	{#snippet brand()}Clínica Norte{/snippet}
	<NavList.Root>
		<NavList.Group>
			<NavList.Item href="/inbox" icon={Inbox}>Inbox</NavList.Item>
		</NavList.Group>
	</NavList.Root>
</Sidebar.Root>

Guidelines

  • Use it once per app, at the start of every screen, for the places the user goes between. Put the actions of a screen on the screen, not here.
  • Fill it with a Nav List: its items keep their names for a screen reader when the sidebar folds to icons.
  • Give every link an icon. Folded, the icon is all that is left of it.
  • Put the product or the clinic in brand, and the account and the settings in footer, away from the places of the app.
  • Keep collapsed with bind:collapsed, and save it, so the sidebar opens the way the user left it.

Accessibility

  • It renders an <aside>. Give it an aria-label, as "Main", when the page has more than one.
  • The fold button is the first tab stop. Its name says what it does, "Collapse the sidebar" or "Expand the sidebar", and it carries aria-expanded and aria-controls for the links.
  • Folded, the brand hides, but the links stay in the tab order with their names.
  • The width moves with no animation when the user asks the system for reduced motion.
  • Change collapseLabel and expandLabel for the language of the page.

API reference

PropTypeDefault
collapsedboolean

Folded to a rail of icons. Bindable.

false
brandSnippet

The product or the clinic, at the head. Hidden while folded.

—
footerSnippet

The account, at the foot, over a rule.

—
childrenSnippet

The links, in a column that scrolls.

—
onCollapsedChange(collapsed: boolean) => void

Called when the fold button folds or unfolds it.

—
collapseLabelstring

The name of the fold button while open.

'Collapse the sidebar'
expandLabelstring

The name of the fold button while folded.

'Expand the sidebar'

Plus every attribute of an <aside>. The parts inside read whether it is folded with getSidebarContext().