Sidebar
HkSidebar is the docked panel a navigation list lives in: a <header> band, a scrolling <body> and a <footer> band, inside a <nav> inside an <aside>. It owns three things a hand-rolled panel keeps getting wrong — an overlay scrollbar that follows the body through density changes, a scroll position that survives a collapse, and, with collapsible, the whole icon-rail capability: the hover-revealed toggle, the hover-peek drawer and the width handoff between the rail and full densities.
- With mobile the same panel becomes a full-screen drawer: the host toggles it, and a click on the overlay area emits close.
- The rows inside the body are NavItems, or a whole band of them from NavSidebar. A breadcrumb trail above the page is Breadcrumb.
- This page is Vue-only: the Rust crate's Sidebar is an unrelated legacy component, documented on Sidebar (legacy), so no mirror of this panel exists. For the rail switch itself see SidebarRailToggle; for its content handoff, SidebarRailSwap.
Import
import { HkSidebar, type HkSidebarSlots, useSidebarRail } from "@celestia-island/hikari";
Bands, width and slots
Three slots fill the panel: header (a fixed band above the body), default (the scrolling body) and footer (a fixed band below it). Any of them may be omitted; the body always takes the space between the bands that exist.
width is the layout width at full width (default 280px) and collapsedWidth the icon-rail width (default 56px). While the panel is docked, both the host's inline width and the panel's own width are written inline, so the panel sizes itself inside whatever column the host gives it and the collapse animates a width rather than remounting the layout. The rail width also feeds the stylesheet's --hk-sidebar-rail-w token, which computes the body's inline padding so an icon-only row stays an exact square whatever width you choose.
The content column keeps its own layout.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { HkSidebar, HkNavItem } from "@celestia-island/hikari";
import { Cable, LayoutDashboard, Settings } from "lucide-vue-next";
import type { CSSProperties } from "vue";
const frame: CSSProperties = { height: "320px", display: "flex", background: "#eef2f7" };
const content: CSSProperties = { flex: 1, padding: "24px" };
export default () => (
<div style={frame}>
<HkSidebar width="248px">
{{
header: () => <strong>Acme</strong>,
default: () => (
<nav>
<HkNavItem active to="/dashboard" v-slots={{ icon: () => <LayoutDashboard size={16} /> }}>
Overview
</HkNavItem>
<HkNavItem to="/connections" v-slots={{ icon: () => <Cable size={16} /> }}>
Connections
</HkNavItem>
<HkNavItem to="/settings" v-slots={{ icon: () => <Settings size={16} /> }}>
Settings
</HkNavItem>
</nav>
),
footer: () => <small>Signed in as ada@example.com</small>,
}}
</HkSidebar>
<div style={content}>The content column keeps its own layout.</div>
</div>
);
import { HkSidebar, HkNavItem } from "@celestia-island/hikari";
import { Cable, LayoutDashboard, Settings } from "lucide-vue-next";
import type { CSSProperties } from "vue";
const frame: CSSProperties = { height: "320px", display: "flex", background: "#eef2f7" };
const content: CSSProperties = { flex: 1, padding: "24px" };
export default () => (
<div style={frame}>
<HkSidebar width="248px">
{{
header: () => <strong>Acme</strong>,
default: () => (
<nav>
<HkNavItem active to="/dashboard" v-slots={{ icon: () => <LayoutDashboard size={16} /> }}>
Overview
</HkNavItem>
<HkNavItem to="/connections" v-slots={{ icon: () => <Cable size={16} /> }}>
Connections
</HkNavItem>
<HkNavItem to="/settings" v-slots={{ icon: () => <Settings size={16} /> }}>
Settings
</HkNavItem>
</nav>
),
footer: () => <small>Signed in as ada@example.com</small>,
}}
</HkSidebar>
<div style={content}>The content column keeps its own layout.</div>
</div>
);The collapsible rail
collapsible is the opt-in rail capability. Without it the panel is a plain static sidebar: collapsed just switches a presentational 56px rail dress, with no toggle and no peek. With it, four things happen:
- a SidebarRailToggle is mounted inside the panel, straddling its content-facing border, invisible until the region is hovered or focused;
- while collapsed, a pointer resting on the rail for peekDelay ms (default 400) opens the panel as a peek — an overlay that slides out over the content while the layout box stays at rail width, so the content column never shifts;
- leaving the region starts peekGrace (default 150) before the peek closes, and re-entering inside that window cancels it, so a diagonal pointer move does not flicker; Escape closes an open peek immediately;
- collapsed becomes a v-model channel: the toggle flips the internal state and emits update:collapsed. The prop keeps that state in sync when an external change arrives, so a host that persists the flag can keep passing it back.
The body slot is scoped: it receives { collapsed, peeking, closePeek }. collapsed is the density that owns the current generation — render icon-only rows when it is true and full rows when it is false — and closePeek lets a row click dismiss the peek the way a shell's own navigate handler does.
peekDelay and peekGrace are the two timing knobs, and the state machine clamps both at zero. A peekDelay of 0 opens the peek as soon as the pointer arms it, with no dwell; a peekGrace of 0 closes it the moment the pointer leaves, with no re-entry window.
Hover the rail to peek; the content column never shifts.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { HkSidebar, HkNavItem } from "@celestia-island/hikari";
import { Cable, LayoutDashboard, Settings } from "lucide-vue-next";
import { ref } from "vue";
import type { CSSProperties } from "vue";
const frame: CSSProperties = { height: "320px", display: "flex", background: "#eef2f7" };
const content: CSSProperties = { flex: 1, padding: "24px" };
export default () => {
const collapsed = ref(true);
return (
<div style={frame}>
<HkSidebar
collapsible
width="240px"
collapsedWidth="56px"
collapsed={collapsed.value}
onUpdate:collapsed={(value: boolean) => { collapsed.value = value; }}
>
{{
header: () => <strong>{collapsed.value ? "A" : "Acme"}</strong>,
default: (scope: { collapsed: boolean; peeking: boolean }) => (
<nav>
<HkNavItem active to="/dashboard" v-slots={{ icon: () => <LayoutDashboard size={16} /> }}>
{scope.collapsed ? "" : "Overview"}
</HkNavItem>
<HkNavItem to="/connections" v-slots={{ icon: () => <Cable size={16} /> }}>
{scope.collapsed ? "" : "Connections"}
</HkNavItem>
<HkNavItem to="/settings" v-slots={{ icon: () => <Settings size={16} /> }}>
{scope.collapsed ? "" : "Settings"}
</HkNavItem>
</nav>
),
}}
</HkSidebar>
<div style={content}>Hover the rail to peek; the content column never shifts.</div>
</div>
);
};
import { HkSidebar, HkNavItem } from "@celestia-island/hikari";
import { Cable, LayoutDashboard, Settings } from "lucide-vue-next";
import { ref } from "vue";
import type { CSSProperties } from "vue";
const frame: CSSProperties = { height: "320px", display: "flex", background: "#eef2f7" };
const content: CSSProperties = { flex: 1, padding: "24px" };
export default () => {
const collapsed = ref(true);
return (
<div style={frame}>
<HkSidebar
collapsible
width="240px"
collapsedWidth="56px"
collapsed={collapsed.value}
onUpdate:collapsed={(value: boolean) => { collapsed.value = value; }}
>
{{
header: () => <strong>{collapsed.value ? "A" : "Acme"}</strong>,
default: (scope: { collapsed: boolean; peeking: boolean }) => (
<nav>
<HkNavItem active to="/dashboard" v-slots={{ icon: () => <LayoutDashboard size={16} /> }}>
{scope.collapsed ? "" : "Overview"}
</HkNavItem>
<HkNavItem to="/connections" v-slots={{ icon: () => <Cable size={16} /> }}>
{scope.collapsed ? "" : "Connections"}
</HkNavItem>
<HkNavItem to="/settings" v-slots={{ icon: () => <Settings size={16} /> }}>
{scope.collapsed ? "" : "Settings"}
</HkNavItem>
</nav>
),
}}
</HkSidebar>
<div style={content}>Hover the rail to peek; the content column never shifts.</div>
</div>
);
};Scrolling and the mobile drawer
The body is the one scroll region: the header and footer keep their natural height, and the body gets an overlay scrollbar attached to the band, so the chrome is shared with every other scrolling container rather than restyled per panel. A scroll position is saved when the body is replaced and restored on the entering generation, which is why a collapse or a peek no longer snaps a long nav back to the top. The body also ends with a scroll tail (24px by default, --hk-sidebar-scroll-tail) so a fully scrolled list visibly ends above the edge instead of kissing it.
mobile swaps the panel for a fixed, full-viewport drawer with its own backdrop; the component then writes no inline width at all and a click on the backdrop itself (event.target === event.currentTarget) emits close. The mobile shape never lays out collapsed — the drawer is the mobile form, and the rail capability is ignored there rather than half-applied.
Presentational rail: no toggle, no peek.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { HkSidebar, HkNavItem } from "@celestia-island/hikari";
import { LayoutDashboard, Settings } from "lucide-vue-next";
import type { CSSProperties } from "vue";
const frame: CSSProperties = { display: "grid", gap: "24px" };
const band: CSSProperties = { height: "220px", display: "flex", background: "#eef2f7" };
const pane: CSSProperties = { flex: 1, padding: "16px" };
export default () => (
<div style={frame}>
<div style={band}>
<HkSidebar width="200px">
{{
default: () => (
<nav>
<HkNavItem active to="/dashboard" v-slots={{ icon: () => <LayoutDashboard size={16} /> }}>
Overview
</HkNavItem>
<HkNavItem to="/settings" v-slots={{ icon: () => <Settings size={16} /> }}>
Settings
</HkNavItem>
</nav>
),
footer: () => <small>Body scrolls; bands stay put.</small>,
}}
</HkSidebar>
<div style={pane}>Docked panel.</div>
</div>
<div style={band}>
<HkSidebar width="200px" collapsed>
{{
default: () => (
<nav>
<HkNavItem active to="/dashboard" v-slots={{ icon: () => <LayoutDashboard size={16} /> }} />
<HkNavItem to="/settings" v-slots={{ icon: () => <Settings size={16} /> }} />
</nav>
),
}}
</HkSidebar>
<div style={pane}>Presentational rail: no toggle, no peek.</div>
</div>
</div>
);
import { HkSidebar, HkNavItem } from "@celestia-island/hikari";
import { LayoutDashboard, Settings } from "lucide-vue-next";
import type { CSSProperties } from "vue";
const frame: CSSProperties = { display: "grid", gap: "24px" };
const band: CSSProperties = { height: "220px", display: "flex", background: "#eef2f7" };
const pane: CSSProperties = { flex: 1, padding: "16px" };
export default () => (
<div style={frame}>
<div style={band}>
<HkSidebar width="200px">
{{
default: () => (
<nav>
<HkNavItem active to="/dashboard" v-slots={{ icon: () => <LayoutDashboard size={16} /> }}>
Overview
</HkNavItem>
<HkNavItem to="/settings" v-slots={{ icon: () => <Settings size={16} /> }}>
Settings
</HkNavItem>
</nav>
),
footer: () => <small>Body scrolls; bands stay put.</small>,
}}
</HkSidebar>
<div style={pane}>Docked panel.</div>
</div>
<div style={band}>
<HkSidebar width="200px" collapsed>
{{
default: () => (
<nav>
<HkNavItem active to="/dashboard" v-slots={{ icon: () => <LayoutDashboard size={16} /> }} />
<HkNavItem to="/settings" v-slots={{ icon: () => <Settings size={16} /> }} />
</nav>
),
}}
</HkSidebar>
<div style={pane}>Presentational rail: no toggle, no peek.</div>
</div>
</div>
);
API
Vue
Props
Emits
Accessibility
- The panel is an <aside> containing a <nav>; neither gets an accessible name from the component, so the navigation landmark is unnamed. On a page with more than one nav, the host should name the region.
- The rail toggle is a real button named "Collapse sidebar" / "Expand sidebar" and carrying aria-expanded; it is revealed by :focus-within, so Tab into the aside paints it and the next Tab reaches it. When the framework moves focus out of a closing peek, it hands it to the toggle rather than letting it fall to <body>.
- Escape closes an open peek and the panel stops the event so outer layers do not also see it. That binding only exists while collapsible is on and the layout is not mobile.
- The scrolling body is not focusable by default: a keyboard user reaches its content through the rows, but scrolls the body only by focusing something inside it — the panel adds no scroll stop of its own.
- The mobile drawer is a full-viewport overlay with no focus trap and no aria-hidden on the page behind it, so the page underneath stays in the accessibility tree and in the Tab order. Moving focus into the drawer on open, and closing it on Escape, are the host's; the component only reports a backdrop click as close.
- collapsed without collapsible is presentational: nothing announces the rail state, and the labels are whatever the host renders in the body.
Related components
- NavItem — the row the body is normally filled with, in its icon and full densities.
- NavSidebar — a ready-made band of rows, mounted inside this panel in Vue.
- SidebarRailToggle — the circular toggle this panel mounts when collapsible is set.
- SidebarRailSwap — the rail/full content handoff the panel composes internally.
- Breadcrumb — the trail above the content column the panel docks beside.