Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Sidebar

An app's side rail: header, grouped menu, badges and a footer, beside the page.

Installation

pnpm add @heyramzi/ui

Usage

import * as Sidebar from "@heyramzi/ui/shadcn/sidebar";
<Sidebar.Provider>
  <Sidebar.Root collapsible="none">
    <Sidebar.Content>
      <Sidebar.Group>
        <Sidebar.GroupLabel>Workspace</Sidebar.GroupLabel>
        <Sidebar.GroupContent>
          <Sidebar.Menu>
            <Sidebar.MenuItem>
              <Sidebar.MenuButton isActive>Home</Sidebar.MenuButton>
              <Sidebar.MenuBadge>4</Sidebar.MenuBadge>
            </Sidebar.MenuItem>
          </Sidebar.Menu>
        </Sidebar.GroupContent>
      </Sidebar.Group>
    </Sidebar.Content>
  </Sidebar.Root>
  <Sidebar.Inset>The page sits here.</Sidebar.Inset>
</Sidebar.Provider>

Keyboard and accessibility

Key Does
Cmd B Ctrl B Opens or closes the sidebar, anywhere on the page.
  • The shortcut leaves typing alone: in a field it's still bold.
  • The trigger is named "Toggle Sidebar" and reports whether the sidebar is open.
  • The rail on the sidebar's edge is for the pointer only. It skips the Tab order.
  • On a phone the sidebar opens as a sheet, so focus is trapped in it and Esc closes it.

API reference

Sidebar.Provider

open bindable boolean
Default true
onOpenChange (open: boolean) => void
Default () => {}
persist boolean
Default true
False for a sidebar that isn't the app's shell, such as a docs demo: it then writes no state cookie and takes no Cmd+B, so it can't fold the real one.
ref bindable HTMLDivElement | null
Default null
class string
style string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements
Prop Type Default
open bindable boolean true
onOpenChange (open: boolean) => void () => {}
persist

False for a sidebar that isn't the app's shell, such as a docs demo: it then writes no state cookie and takes no Cmd+B, so it can't fold the real one.

boolean true
ref bindable HTMLDivElement | null null
class string
style string
children Snippet
...rest Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements

Sidebar.Root

side "left" | "right"
Default "left"
variant "sidebar" | "floating" | "inset"
Default "sidebar"
collapsible "offcanvas" | "icon" | "none"
Default "offcanvas"
ref bindable HTMLDivElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements
Prop Type Default
side "left" | "right" "left"
variant "sidebar" | "floating" | "inset" "sidebar"
collapsible "offcanvas" | "icon" | "none" "offcanvas"
ref bindable HTMLDivElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements

Sidebar.Header

ref bindable HTMLElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLElement> from svelte/elements
Prop Type Default
ref bindable HTMLElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLElement> from svelte/elements

Sidebar.Content

ref bindable HTMLElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLElement> from svelte/elements
Prop Type Default
ref bindable HTMLElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLElement> from svelte/elements

Sidebar.Group

ref bindable HTMLElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLElement> from svelte/elements
Prop Type Default
ref bindable HTMLElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLElement> from svelte/elements

Sidebar.GroupLabel

child Snippet<[{ props: Record<string, unknown> }]>
ref bindable HTMLElement | null
Default null
children Snippet
class string
...rest
Every prop of HTMLAttributes<HTMLElement> from svelte/elements
Prop Type Default
child Snippet<[{ props: Record<string, unknown> }]>
ref bindable HTMLElement | null null
children Snippet
class string
...rest Every prop of HTMLAttributes<HTMLElement> from svelte/elements

Sidebar.GroupContent

ref bindable HTMLDivElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements
Prop Type Default
ref bindable HTMLDivElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements

Sidebar.Menu

ref bindable HTMLUListElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLUListElement> from svelte/elements
Prop Type Default
ref bindable HTMLUListElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLUListElement> from svelte/elements

Sidebar.MenuItem

ref bindable HTMLLIElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLLIElement> from svelte/elements
Prop Type Default
ref bindable HTMLLIElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLLIElement> from svelte/elements

Sidebar.MenuButton

isActive boolean
Default false
variant "default" | "outline"
Default "default"
size "default" | "sm" | "lg"
Default "default"
tooltipContent Snippet | string
tooltipContentProps WithoutChildrenOrChild<ComponentProps<typeof Tooltip.Content>>
child Snippet<[{ props: Record<string, unknown> }]>
ref bindable HTMLButtonElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLButtonElement> from svelte/elements
Prop Type Default
isActive boolean false
variant "default" | "outline" "default"
size "default" | "sm" | "lg" "default"
tooltipContent Snippet | string
tooltipContentProps WithoutChildrenOrChild<ComponentProps<typeof Tooltip.Content>>
child Snippet<[{ props: Record<string, unknown> }]>
ref bindable HTMLButtonElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLButtonElement> from svelte/elements

Sidebar.MenuBadge

ref bindable HTMLElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLElement> from svelte/elements
Prop Type Default
ref bindable HTMLElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLElement> from svelte/elements
ref bindable HTMLElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLElement> from svelte/elements
Prop Type Default
ref bindable HTMLElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLElement> from svelte/elements

Sidebar.Inset

ref bindable HTMLElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLElement> from svelte/elements
Prop Type Default
ref bindable HTMLElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLElement> from svelte/elements

Sidebar.GroupAction

child Snippet<[{ props: Record<string, unknown> }]>
ref bindable HTMLButtonElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLButtonAttributes from svelte/elements
Prop Type Default
child Snippet<[{ props: Record<string, unknown> }]>
ref bindable HTMLButtonElement | null null
class string
children Snippet
...rest Every prop of HTMLButtonAttributes from svelte/elements

Sidebar.Input

ref bindable Input
Default null
value bindable string
Default ""
class string
...rest
Every prop of Input
Prop Type Default
ref bindable Input null
value bindable string ""
class string
...rest Every prop of Input

Sidebar.MenuAction

child Snippet<[{ props: Record<string, unknown> }]>
showOnHover boolean
Default false
ref bindable HTMLButtonElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLButtonAttributes from svelte/elements
Prop Type Default
child Snippet<[{ props: Record<string, unknown> }]>
showOnHover boolean false
ref bindable HTMLButtonElement | null null
class string
children Snippet
...rest Every prop of HTMLButtonAttributes from svelte/elements

Sidebar.MenuSkeleton

showIcon boolean
Default false
ref bindable HTMLElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLElement> from svelte/elements
Prop Type Default
showIcon boolean false
ref bindable HTMLElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLElement> from svelte/elements

Sidebar.MenuSub

ref bindable HTMLUListElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLUListElement> from svelte/elements
Prop Type Default
ref bindable HTMLUListElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLUListElement> from svelte/elements

Sidebar.MenuSubButton

child Snippet<[{ props: Record<string, unknown> }]>
size "sm" | "md"
Default "md"
isActive boolean
Default false
ref bindable HTMLAnchorElement | null
Default null
children Snippet
class string
...rest
Every prop of HTMLAnchorAttributes from svelte/elements
Prop Type Default
child Snippet<[{ props: Record<string, unknown> }]>
size "sm" | "md" "md"
isActive boolean false
ref bindable HTMLAnchorElement | null null
children Snippet
class string
...rest Every prop of HTMLAnchorAttributes from svelte/elements

Sidebar.MenuSubItem

ref bindable HTMLLIElement | null
Default null
children Snippet
class string
...rest
Every prop of HTMLAttributes<HTMLLIElement> from svelte/elements
Prop Type Default
ref bindable HTMLLIElement | null null
children Snippet
class string
...rest Every prop of HTMLAttributes<HTMLLIElement> from svelte/elements

Sidebar.Rail

label string
Default "Toggle Sidebar"
The rail's name and hover tooltip, in the app's language.
ref bindable HTMLButtonElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLButtonElement> from svelte/elements
Prop Type Default
label

The rail's name and hover tooltip, in the app's language.

string "Toggle Sidebar"
ref bindable HTMLButtonElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLButtonElement> from svelte/elements

Sidebar.Separator

ref bindable Separator
Default null
class string
...rest
Every prop of Separator
Prop Type Default
ref bindable Separator null
class string
...rest Every prop of Separator

Sidebar.Trigger

onclick (e: MouseEvent) => void
label string
Default "Toggle Sidebar"
What a screen reader calls the icon-only button, in the app's language.
ref bindable Button
Default null
class string
...rest
Every prop of Button
Prop Type Default
onclick (e: MouseEvent) => void
label

What a screen reader calls the icon-only button, in the app's language.

string "Toggle Sidebar"
ref bindable Button null
class string
...rest Every prop of Button