SidebarRailSwap
HkSidebarRailSwap is the content handoff of a collapsible sidebar: you give it the two densities of a sidebar body — the icon rail and the full-width column — and it swaps them through an opacity dissolve, each generation pinned at its own width. It closes the defect every hand-rolled rail had: the panel's width animates while the density changes instantly, so a single mounted body is re-laid-out at an animating width — full-width rows squeeze into a still-56px panel on expand and glide out of a still-wide one on collapse.
- The swap is the CONTENT half of the rail capability; the hover toggle that drives it is SidebarRailToggle, and the clipping container the swap must sit in is the rail host's .hk-sidebar-rail-clip (see the host contract below). Sidebar mounts both when collapsible is set, so you only assemble this by hand in a bespoke host.
- For two views that simply exchange in place with no width involved, the underlying dissolve is HkCrossfade — this component composes it rather than inventing a second fade.
- For a sidebar whose sections collapse to headers inside one column, that is an accordion, not a density flip; this component only exchanges one body for another.
Import
;
use *; // SidebarRailSwap, SidebarRailSwapProps
use *; // rsx!, VNode, EventHandler
The Rust form is a plain function, SidebarRailSwap(SidebarRailSwapProps { … }). Every prop may be omitted inside rsx!; an omitted rail is false and the widths default to 56px / 280px, exactly the Vue defaults. The Rust form of the swap is controlled, not self-driving: a host that wants the dissolve passes phase / previous / previous_key through to its own state machine (see the last section).
Two generations, one dissolve
rail picks which generation is on stage: true is the icon rail (the collapsed density), false is the full sidebar, a peek included. The generation renders inside a keyed item whose data-crossfade-key is "rail" or "full", and the rail generation — and only the rail generation — carries data-rail="true". Scope your density dress to that wrapper, never to the swap root: a host-level attribute flips with the state and would restyle the frozen leaving copy mid-dissolve.
The widths are opaque CSS strings pinned inline on the generation. Leaving them unset uses 56px / 280px; a var() reference passes straight through, so a host that retunes its panel width through a token only has to hand the same token in. Give the swap the width its panel actually rests at — the sheet shrinks the swap to fit the widest generation, which is what makes the "original content width" guarantee structural rather than per-frame.
The TSX sample below drives rail from a checkbox so the exchange can be watched; the Rust sample is the two settled states side by side, because a snapshot never runs an event handler.
The host contract
The swap emits two classes that belong to the rail family's shared sheet, not to its own: hk-sidebar-rail-swap rides the dissolve root and hk-sidebar-rail-generation wraps the body. Neither is declared here — the Vue component imports HkSidebarRail.scss for the geometry and ships no sheet of its own, and the Rust mirror's styles() is empty for the same reason. Two rules follow from that, and a host has to hold both up:
- The swap must be a direct child of .hk-sidebar-rail-clip. The sheet's sizing rule is a child combinator; a swap nested one level deeper gets no flex track and collapses to its content width inside the clipping column.
- The clip needs an ancestor .hk-sidebar-rail-host, which is what carries the panel width and the rail's tokens.
Below is that structure in miniature: the clip is given a 120px window, and each generation inside is pinned at its own width (56px for the rail, 200px for the full one), so the clip has something to cut. The Rust sample renders both generations in that one clip side by side — rsx! cannot branch on a host variable inside the element, and a let may not live inside it either, so the two bodies are built before the rsx!.
What a flip costs, and what the two forms differ on
Each flip mounts the entering generation fresh, the same way a tab-panel swap does: a scrolled body starts the entering copy at the top, and uncontrolled state inside the slot does not carry over. Hosts that need state to survive a flip lift it above the swap (a provide/inject store) instead of keeping it in an instance ref inside the slot. A menu's own fold state is the documented exception and is not this component's doing — the rail shell keeps it above the swap.
Focus is the other cost. When the dissolve ends the leaving generation unmounts with inert and aria-hidden on it, so a focused descendant is blurred; the rail kit's own close paths hand focus to the toggle, but a bespoke host that drives its own close paths owns that handoff. While the dissolve runs, both generations are on screen and the leaving one drops pointer events.
The icon-flight layer — icons sliding from their expanded position into the rail column — is Vue-side only, through useRailIconFlight; it is not part of the swap's own props, and an opted-in icon must carry data-flip-icon="<row key>" (stamped by the menus) to take part. [D] The Rust mirror declares the flight vocabulary and its timing maths (RAIL_FLIP_ICON_ATTR, rail_flight_window_ms, rail_flight_sweep_ms and friends) but ships no flight: the shipped artifact has no DOM to measure or clone, so the dissolve is the handoff there.
[D] The dissolve itself is controlled in Rust rather than owned: the mirrored Crossfade has no transition hooks, so the swap forwards phase / previous / previous_key and at the Idle default exactly one generation is mounted. [D] The default slot's { rail } parameter has no tairitsu equivalent — children is rendered as given, so the host branches on the same rail value itself. [D] An empty width renders no inline width at all in Rust (Vue would emit an empty style="").
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| rail | Boolean | false | — |
| railWidth | String | "56px" | — |
| expandedWidth | String | "280px" | — |
Rust
Props — SidebarRailSwap
| Prop | Type | Default | Description |
|---|---|---|---|
| rail | bool | false | Which generation is active: true = the icon rail (the collapsed density), false = the full sidebar (including a peek). |
| rail_width | String | "56px".to_string() | Pinned width of the RAIL generation (Vue: railWidth, default 56px). |
| expanded_width | String | "280px".to_string() | Pinned width of the EXPANDED generation (Vue: expandedWidth, default 280px) — a CSS length or a var() reference. |
| phase | CrossfadePhase | CrossfadePhase::Idle | The controlled crossfade phase (see the header delta): Idle renders the settled single-generation state. |
| previous_key | Option<String> | None | Key of the generation the host is still holding for the dissolve (Vue: the leaving item's key, owned by <Transition>). |
| previous | Option<Element> | None | The frozen outgoing generation (Vue: <Transition>'s retained vnode). |
| children | Element | (empty) | The generation's content (Vue: the default slot; see the header delta about the scoped { rail } parameter). |
| class | String | "" | Fallthrough host class, appended after hk-sidebar-rail-swap (Vue's attr merge onto HkCrossfade's root). |
Accessibility
- The swap adds no role, name or landmark of its own; the generation wrapper is a plain <div>, so the sidebar's own semantics (<nav>, aria-label, the list of links) travel with the body you render into it.
- The leaving generation carries inert and aria-hidden for the length of the dissolve, so a screen-reader user hears one sidebar, never a stale duplicate of it, and a Tab press cannot reach the frozen copy.
- Because that freeze blurs anything focused inside the leaving copy, move focus deliberately on a collapse: the rail kit hands it to its toggle when the focused node lived inside the swapped window — the toggle is the control the user needs next.
- Reduced motion keeps a short opacity exchange and kills the width slides, so the handoff degrades to a quick dip; it never squeezes the content, which is the whole point of pinning each generation at its own width.
Related components
- SidebarRailToggle — the circular hover toggle that flips rail on the rail host.
- Sidebar — the panel that mounts the toggle and this swap when it is collapsible.
- DockBar — floating chrome for an edge; the swap is in-flow panel content instead.
- ScrollContainer — the scroll region a long sidebar body is usually put inside.
- HkCrossfade — the same-position dissolve primitive this component is built on.