Sidebar
The app's column of navigation, with a head, the links and a foot, folding to a rail of icons.
The page.
Installation
pnpm dlx @human-kit/design add sidebarnpx @human-kit/design add sidebaryarn dlx @human-kit/design add sidebarbunx @human-kit/design add sidebarThe 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 infooter, away from the places of the app. - Keep
collapsedwithbind:collapsed, and save it, so the sidebar opens the way the user left it.
Accessibility
- It renders an
<aside>. Give it anaria-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-expandedandaria-controlsfor 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
collapseLabelandexpandLabelfor the language of the page.
API reference
| Prop | Type | Default |
|---|---|---|
collapsed | boolean Folded to a rail of icons. Bindable. | false |
brand | Snippet The product or the clinic, at the head. Hidden while folded. | — |
footer | Snippet The account, at the foot, over a rule. | — |
children | Snippet The links, in a column that scrolls. | — |
onCollapsedChange | (collapsed: boolean) => void Called when the fold button folds or unfolds it. | — |
collapseLabel | string The name of the fold button while open. | 'Collapse the sidebar' |
expandLabel | string 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().