SidebarRailToggle
HkSidebarRailToggle is the small circular button that collapses a sidebar to its icon rail and lets it back out. It straddles the panel's content-facing border — the circle's centre sits on the border line, so half of it hangs over the content — and it is invisible and unclickable until the sidebar region is hovered or focused. The geometry, the reveal and the fade live in the rail stylesheet, not in this component's markup.
- The control belongs to a rail-capable panel. In Vue, Sidebar's collapsible prop mounts it for you and wires the click to the rail state machine; this page documents the button you get when a host places it itself.
- The content handoff between the rail and full-width densities is SidebarRailSwap; this component only asks for the flip. The panel and the state machine are Sidebar.
- This is a chrome control, not a navigation row: for the rows inside the panel use NavItem or NavSidebar.
Import
;
use *; // SidebarRailToggle, RailToggleAction, is_pointer_over_rail_toggle
use *; // rsx!, VNode, EventHandler
The Rust form is a plain function, SidebarRailToggle(SidebarRailToggleProps { … }). Inside rsx! every prop may be omitted, and an omitted expanded is true — the same default as Vue.
The state, and the glyph direction
expanded describes the sidebar, not the button: true (the default) means the panel is at full width and a press will collapse it, false means it is an icon rail and a press will expand it. A press emits toggle with no payload; the component does not flip anything itself, so the host owns the state and passes the new value back.
The glyph follows that direction — and it is the direction of the action, not of the panel. At full width the button shows the two chevrons converging (›‹, "squeeze the sidebar in"); on the rail it shows them diverging (‹›, "let it back out"). The pair is mirror-symmetric, so a right-to-left layout needs no glyph flip, and the chevrons are drawn without a shaft so they read as a squeeze rather than as arrows to a destination.
The Vue sample is live: a press emits toggle and the host flips its own flag, which reverses the glyph and the label. The Rust snapshot is a still — it runs no handler — so it shows both states side by side; a live host stores expanded the same way and receives the flip through on_toggle.
Either sample is drawn against a plain light box rather than a real sidebar, so nothing is hovered and the region has no hk-sidebar-rail-host class: the two circles sit at opacity: 0. They are the live control, faded out — move the pointer over the box (or Tab into it) and they appear.
Where it has to sit: the reveal, and the hit test
The button is opacity: 0; pointer-events: none until its ancestor region is engaged. The reveal selectors are anchored on an ancestor carrying hk-sidebar-rail-host:
}
So on a host that does not carry that class the control renders invisible and unreachable — present in the markup, but neither seen nor clickable. Sidebar stamps the class itself when collapsible is set; a bespoke host must add it. The same class declares the geometry tokens the circle's position reads (--hk-sidebar-rail-toggle-size: 24px, --hk-sidebar-rail-border-width: 1px), so a retune has to land on the host or between the host and the toggle, never on an ancestor above it.
Because the circle sits on the rail's own hover surface, a pointer resting on the button would otherwise arm the panel's hover-peek and open the drawer under the cursor. Hosts prevent that by feeding a geometric containment test into the state machine: isPointerOverRailToggle(host, x, y) looks up .hk-sidebar-rail-toggle inside the host and reports whether the point is within two pixels of its box. Geometry rather than event.target is deliberate — before the reveal the button is pointer-events: none, so the pointer's target is the element underneath and a containment test on the target would say "not on the toggle".
The host above carries its own class names only for the demo (it does not set hk-sidebar-rail-host), so the button is shown here by the document's own styles; the hit test is the part worth reading — it is the same call Sidebar makes on every pointer move and enter.
Accessible name and state
The circle is a standard icon button at its 24px step with the ghost variant, and the chevron pair is 14px. The round shape is not built in: .hk-icon-button draws its corners from --hi-icon-button-radius, which defaults to the 8px corner. The rail stylesheet re-points that variable on .hk-sidebar-rail-toggle .hk-icon-button, so the button is circular only inside a .hk-sidebar-rail-toggle wrapper — which this component always renders.
The accessible name comes from the translation table and follows the state — hikari::sidebar.collapse ("Collapse sidebar") at full width, hikari::sidebar.expand ("Expand sidebar") on the rail — so the button always describes the action it will perform. aria-expanded is always rendered as the literal "true" / "false", while the wrapper's data-expanded attribute is present only at full width; the state markup is for the stylesheet, and the ARIA state for assistive technology.
The name resolves by lookup, so the strings are the same in both forms; the Rust mirror reads its own bundle keys (components.hk.sidebarRailToggle.*) with the same English as fallback, and the two key families have to be kept in step by whoever ships locale entries.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| expanded | Boolean | true | — |
Emits
| Event | Payload |
|---|---|
| toggle | — |
Rust
Props — SidebarRailToggle
| Prop | Type | Default | Description |
|---|---|---|---|
| expanded | bool | true | True while the sidebar is at FULL width (clicking will collapse); false while it is an icon rail (clicking will expand). |
| on_toggle | Option<EventHandler<()>> | None | The toggle emit (Vue: emits: { toggle: () => true }, no payload). |
| class | String | "" | Fallthrough host class on the positioning wrapper (Vue: the single-root attr merge). |
Accessibility
- The control is a real <button type="button">, so it is reached by Tab, pressed with Enter or Space, and never submits a form.
- Its name always states the action for the current state ("Collapse sidebar" / "Expand sidebar"), which is what a screen-reader user needs before pressing it; the chevrons themselves are aria-hidden.
- aria-expanded mirrors the state on both sides. Note the direction: it reports whether the sidebar is expanded, so at full width the button announcing "Collapse sidebar" is also aria-expanded="true" — consistent with a disclosure control, but the name and the state point opposite ways — that opposition follows by construction from labelling the action while publishing the panel state, and it is not a bug.
- The keyboard path to the button runs through the region's :focus-within reveal: Tab into the sidebar makes the circle visible, and Tab reaches it in document order (it is the panel's last child, after the clip). A bespoke host that renders the toggle outside a focusable region loses that affordance.
- Pressing Escape while the hover-peek drawer is open closes the peek; that binding belongs to the state machine in Sidebar, not to the button.
- The circle's box is 24px, which is below the 44px touch-target guideline. Its ring is drawn by the stylesheet with a hairline shadow, and its ink-changes on hover and focus come from the icon-button family, so it stays legible at that size — but on a touch-only layout the host should place it in a larger hit area.
Related components
- Sidebar — the rail-capable panel that mounts this button, reveals it and owns the collapse state.
- SidebarRailSwap — the rail/full content handoff a flip drives.
- NavItem — the rows inside the panel, in their icon and full densities.
- NavSidebar — a ready-made band of those rows.