Sidebar
An app's side rail: header, grouped menu, badges and a footer, beside the page.
Installation
pnpm add @heyramzi/uiUsage
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
openbindableboolean- Default
true onOpenChange(open: boolean) => void- Default
() => {} persistboolean- 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.
refbindableHTMLDivElement | null- Default
null classstringstylestringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/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" refbindableHTMLDivElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/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
refbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLElement> from svelte/elements | |
Sidebar.Content
refbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLElement> from svelte/elements | |
Sidebar.Group
refbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLElement> from svelte/elements | |
Sidebar.GroupLabel
childSnippet<[{ props: Record<string, unknown> }]>refbindableHTMLElement | null- Default
null childrenSnippetclassstring...rest- Every prop of
HTMLAttributes<HTMLElement>fromsvelte/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
refbindableHTMLDivElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLDivElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements | |
Sidebar.Menu
refbindableHTMLUListElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLUListElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLUListElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLUListElement> from svelte/elements | |
Sidebar.MenuItem
refbindableHTMLLIElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLLIElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLLIElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLLIElement> from svelte/elements | |
Sidebar.MenuButton
isActiveboolean- Default
false variant"default" | "outline"- Default
"default" size"default" | "sm" | "lg"- Default
"default" tooltipContentSnippet | stringtooltipContentPropsWithoutChildrenOrChild<ComponentProps<typeof Tooltip.Content>>childSnippet<[{ props: Record<string, unknown> }]>refbindableHTMLButtonElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLButtonElement>fromsvelte/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
refbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLElement> from svelte/elements | |
Sidebar.Footer
refbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLElement> from svelte/elements | |
Sidebar.Inset
refbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLElement> from svelte/elements | |
Sidebar.GroupAction
childSnippet<[{ props: Record<string, unknown> }]>refbindableHTMLButtonElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLButtonAttributesfromsvelte/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
refbindableInput- Default
null valuebindablestring- Default
"" classstring...rest- Every prop of
Input
| Prop | Type | Default |
|---|---|---|
ref bindable | Input | null |
value bindable | string | "" |
class | string | |
...rest | Every prop of Input | |
Sidebar.MenuAction
childSnippet<[{ props: Record<string, unknown> }]>showOnHoverboolean- Default
false refbindableHTMLButtonElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLButtonAttributesfromsvelte/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
showIconboolean- Default
false refbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLElement>fromsvelte/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
refbindableHTMLUListElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLUListElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLUListElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLUListElement> from svelte/elements | |
Sidebar.MenuSubButton
childSnippet<[{ props: Record<string, unknown> }]>size"sm" | "md"- Default
"md" isActiveboolean- Default
false refbindableHTMLAnchorElement | null- Default
null childrenSnippetclassstring...rest- Every prop of
HTMLAnchorAttributesfromsvelte/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
refbindableHTMLLIElement | null- Default
null childrenSnippetclassstring...rest- Every prop of
HTMLAttributes<HTMLLIElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLLIElement | null | null |
children | Snippet | |
class | string | |
...rest | Every prop of HTMLAttributes<HTMLLIElement> from svelte/elements | |
Sidebar.Rail
labelstring- Default
"Toggle Sidebar" - The rail's name and hover tooltip, in the app's language.
refbindableHTMLButtonElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLButtonElement>fromsvelte/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
refbindableSeparator- Default
null classstring...rest- Every prop of
Separator
| Prop | Type | Default |
|---|---|---|
ref bindable | Separator | null |
class | string | |
...rest | Every prop of Separator | |
Sidebar.Trigger
onclick(e: MouseEvent) => voidlabelstring- Default
"Toggle Sidebar" - What a screen reader calls the icon-only button, in the app's language.
refbindableButton- Default
null classstring...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 | |