Skip to content
portalbits
Home Docs GitHub(opens in a new tab)

Guides

Get startedFoundationsMotion

Components

All components

Buttons

ButtonIconButton

Inputs

InputSelectTextareaSlider

Selection

CheckboxToggleToggleGroupSwitchRadioGroup

Identity

AvatarBadge

Overlays

DialogPopoverTooltipDropdownMenuAlertDialog

Disclosure

TabsAccordion

Cards

AppCardArticleCardFeatureCard

Content

CarouselSectionHeaderEmptyStateAlertProgressSeparatorRowListRow

Chrome

PortalShellSidebarNavMobileNavTopBarAuthFrameColorSelectorFloatingNav

SidebarNav

Desktop navigation with an active item and an optional count.

OverviewFoundationsComponents29
Variations

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

NameTypeDefaultRequiredBindingDescription
itemsNavItem[]NoneYesOne-wayNavigation items as `{ href, label, icon?, count? }`.
activestringNoneYesOne-wayThe `href` of the current item. It gets `aria-current="page"`.
collapsedbooleanfalseNoOne-wayShows 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.

Related

  • MobileNav
  • PortalShell
Previous PortalShell Next MobileNav

On this page

  • Preview
  • Source
  • API reference
  • Props
  • Forwarded attributes
  • Limits