SidebarNav
Desktop navigation with an active item and an optional count.
Source
<script lang="ts">
import 'portal-bits/styles.css';
import 'portal-bits/tokens.css';
import type { Snippet } from 'svelte';
let { children }: { children: Snippet } = $props();
</script>
{@render children()}
<script lang="ts">
import SidebarNavExample from './SidebarNavExample.svelte';
</script>
<SidebarNavExample collapsed={false} />
<script lang="ts">
import { SidebarNav, type NavItem } from 'portal-bits';
// This example uses @lucide/svelte for the navigation icons. Omit `icon` to skip it.
import { Component, Layers, LayoutGrid } from '@lucide/svelte';
let { collapsed = false }: { collapsed?: boolean } = $props();
const items: NavItem[] = [
{ href: '#overview', label: 'Overview', icon: LayoutGrid },
{ href: '#foundations', label: 'Foundations', icon: Layers },
{ href: '#components', label: 'Components', icon: Component, count: '29' },
];
// The consumer supplies the active URL. In SvelteKit, use the current pathname.
const active = '#components';
</script>
<div class="slice">
<SidebarNav {items} {active} {collapsed} />
</div>
<style>
.slice {
max-width: 280px;
padding: 12px;
border-radius: 16px;
background: var(--portal-canvas);
}
</style>
API reference
These tables list the props and snippets that SidebarNav declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.
Props
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
items | NavItem[] | None | Yes | One-way | Navigation items as `{ href, label, icon?, count? }`. |
active | string | None | Yes | One-way | The `href` of the current item. It gets `aria-current="page"`. |
collapsed | boolean | false | No | One-way | Shows icons only. Each link keeps its name and a title. |
Forwarded attributes
None. SidebarNav forwards no attributes.
No data attributes are documented as stable.
Limits
- The `nav` is always named "Main navigation".
- The count is hidden when collapsed.
- Every item is a plain anchor. Client routing belongs to your router.