Sidebar (legacy)
Sidebar is a legacy migration surface: the Rust crate's multi-level navigation tree — a <nav aria-label="Sidebar navigation"> whose children are SidebarSections, SidebarItems and SidebarLeafs, each level folding its own children. It keeps existing Rust pages building; new code should prefer the Vue panel, HkSidebar.
The three row components have no pages of their own, so this page documents them with the container that provides their selection context.
- The two are not mirrors of each other, despite the shared name. HkSidebar is a Vue-only panel: an <aside> with header / footer slots, a collapsible icon rail with a hover peek, and it renders no rows at all — a host puts a menu inside it. This Sidebar is a Rust <nav> that ships its own tree of sections, items and leaves. The same name in the two languages means two different components.
- Reach for it while migrating a Rust page that already renders this shape; on a new surface use HkSidebar, which owns the frame and leaves the navigation to the menu it wraps.
- A path trail rather than a tree is Breadcrumb (legacy); an in-page rail over the same document is Anchor.
Import
use *; // Sidebar, SidebarItem, SidebarLeaf, SidebarSection
use *; // SidebarProps, SidebarSectionProps, SidebarItemProps, SidebarLeafProps, rsx!, VNode
Each is a plain function taking its props struct: Sidebar(SidebarProps { … }), SidebarSection(SidebarSectionProps { … }), and so on for the other two. All four props structs are in the prelude, and every field of all four has a default — a row with no id and no title is legal and renders empty. The one thing that has to be spelled deliberately is a nested slot: on SidebarSection and SidebarLeaf the children field is written bare (children: rsx! { … }), while on SidebarItem it is the items: Option<Element> slot written as Some(rsx! { … }); SidebarItem's content slot is likewise Some(…).
The container and the selection context
Sidebar renders a <nav class="hk-sidebar"> with role="navigation" and the hard-coded aria-label="Sidebar navigation", appends class, and — the part that makes the rows work — provides a SidebarContext to everything below it: the current active_id and an on_select callback. A SidebarLeaf reads that context, compares its own id against active_id, marks itself data-active="true" when they match, and on a click calls on_select with its id.
So the shape is Sidebar { active_id, on_select, … rows … } and the host owns the state: pressing a leaf reports the id, and the host passes the new active_id back. Not being a context item, a SidebarItem never reports a press.
The sheet gives the panel width: 100% and height: 100%, so it fills whatever box the host gives it; with no sized parent it collapses to its content in a document flow.
Sections, items and leaves
SidebarSection is the top-level group: a clickable header (div.hk-sidebar-section-header, holding the title, an optional secondary_title and a chevron) that toggles a data-expanded attribute on the children container, whose aria-hidden follows the same state. default_expanded is the initial value and is also the value a snapshot shows; class is appended after the section's own and is the section's only styling hook.
SidebarItem is the middle level: an always-visible header, an optional content element (a host a, a badge, anything the row should show instead of the label) and an optional items element — the nested rows. Only an item that has items gets a chevron, and only then does the header toggle: an item without children is clickable but inert.
SidebarLeaf is the terminal row: a div with role="button", tabindex="0", data-id, data-active and its children (plus an optional secondary_label). It is the row that reports selection.
Nesting is arbitrary: each additional .hk-sidebar-item-children level adds 0.5rem of indentation to the header's padding, up to the fourth level's rule.
Host content inside a row, and host classes
SidebarItem's content slot replaces the label markup wholesale; the sheet makes a descendant a fill the whole header row by positioning it against the row's padding, so a host link gets a full-width hit area. SidebarLeaf has no content slot — its children are the row's body — so a link there is the host's own <a> inside the children, and it is the anchor, not the div, that the pointer lands on.
All four components take class; on a row it is appended after the row's own classes, which is the only styling hook the family has — there is no style prop anywhere in it.
on_select is a Callback<String>: the sample gives it one that writes the id into a host signal, which is the wiring a live page uses. A snapshot never runs it — the marks in the sample come from active_id alone.
API
Rust
Props — Sidebar
| Prop | Type | Default | Description |
|---|---|---|---|
| active_id | String | "".to_string() | — |
| on_select | Option<Callback<String>> | None | Called with the clicked leaf's id. |
| class | String | "".to_string() | — |
| children | Element | VNode::empty() | — |
Props — SidebarSection
| Prop | Type | Default | Description |
|---|---|---|---|
| id | String | "".to_string() | — |
| title | String | "".to_string() | — |
| secondary_title | Option<String> | None | — |
| default_expanded | bool | false | — |
| class | String | "".to_string() | — |
| children | Element | VNode::empty() | — |
Props — SidebarItem
| Prop | Type | Default | Description |
|---|---|---|---|
| id | String | "".to_string() | — |
| label | String | "".to_string() | — |
| secondary_label | Option<String> | None | — |
| default_expanded | bool | false | — |
| class | String | "".to_string() | — |
| content | Option<Element> | None | — |
| items | Option<Element> | None | — |
Props — SidebarLeaf
| Prop | Type | Default | Description |
|---|---|---|---|
| id | String | "".to_string() | — |
| secondary_label | Option<String> | None | — |
| class | String | "".to_string() | — |
| children | Element | VNode::empty() | — |
Accessibility
- The container is a real <nav> with an aria-label, and the summary the region announces is the hard-coded "Sidebar navigation" — every instance on a page has the same name, and a host cannot rename it.
- Only a leaf is in the tab order (role="button", tabindex="0"); sections and items are plain divs with an onclick, so the fold is pointer-only. There is no key handling on a leaf either: Enter and Space do nothing, because nothing turns the key press into a click.
- A leaf announces itself as a button with the row's text as its name, but nothing says which row is current: data-active is an attribute the sheet reads for the tint, and no aria-current or aria-pressed is written.
- A collapsed section's children are display: none plus aria-hidden="true", so they leave both the reading and the tab order together — consistent, but the header itself still exposes no expanded state to a screen reader (aria-expanded is set on the header div, which has no button role to carry it).
- The chevrons are decorative SVGs from the icon set with no aria-hidden; they add no name to any row.
- The Vue panel HkSidebar solves the frame (an <aside> with header and footer slots, a rail, a mobile drawer); its navigation rows come from the menu the host mounts inside it.
Related components
- HkSidebar — the Vue panel with the same name; the frame for new surfaces, and not a mirror of this component.
- Breadcrumb (legacy) — the Rust path trail, when the location is a path rather than a tree.
- Anchor — the in-page rail over one document.
- Layout — the legacy page frame whose Aside is the column this panel is usually dropped into.