Collapse (legacy)

Collapse (legacy)

Collapse is a legacy migration surface: a Rust-only disclosure that folds a block of host content away behind a clickable header. One call renders div.hk-collapse → a div.hk-collapse-header (a text chevron and a header slot) → a div.hk-collapse-content whose max-height and opacity animate between 0 and 1000px / 0 and 1. packages/vue/src ships nothing by that name.

  • The content appears twice. The children element is rendered in both the header and the body — that is what the source does, and it is the main reason not to build a new surface on this component. Read "The same children, twice" below before you use it.
  • New surfaces fold with JsonTree's own collapses (JSON payloads), TreeNode's open rows, or a plain v-if / if in the host; the Vue library folds with a <Transition> the host writes.
  • A run of collapsible groups in one panel is a host pattern here, not a component: this is one group, with no accordion coordination, no icon and no aria-expanded.

Import

rust
1
2
use hikari_components::*;          // Collapse, CollapseComponent
use hikari_components::prelude::*; // CollapseProps, rsx!, VNode

Collapse is a plain function, Collapse(CollapseProps { … }). Every prop has a default except children, so inside rsx! the children are the only thing that must be passed: expanded defaults to false, duration to 200 (milliseconds), animated to true, class to "" and on_expand to None. CollapseProps is in the prelude; CollapseComponent (the stylesheet handle) is not, and a page almost never needs it.

The header, the chevron and the open flag

The header is a div with a hard-coded inline style that makes it look clickable (cursor: pointer, a flex row, an 8px gap) and an onclick that flips the internal open signal and then reports the new value through on_expand: Option<EventHandler<bool>>. The chevron is the literal text "›" in span.hk-collapse-arrow, rotated 0deg when closed and 90deg when open by an inline transform, with the rotation duration taken from duration.

The open flag is private: expanded seeds a signal (use_signal(() => props.expanded)) and nothing reads it back. A host can therefore set the initial state but cannot close a group from outside, cannot know what the user did except through on_expand, and cannot keep several groups in step.

animated: false removes the transition string but not the open/closed difference: the height and opacity still switch, they just switch instantly.

Rust
›Deployment settings
Deployment settings
›Worker pool
Worker pool

The snapshot is a still: expanded: true draws the open state and the press handler is never run.

The same children, twice

props.children is cloned into the header slot (span.hk-collapse-header-content) and into the body (div.hk-collapse-inner). With a single text child that reads acceptably by accident — the same words appear as the header title and again as the body — but with any structured content the block is duplicated: two copies of every control, two of every heading, two sets of ids. The component offers no separate header prop, so a host cannot pass "a title here, a body there".

Read together with the fold, this also means the header grows and shrinks with the body — a closed group shows its content as its title. If you inherit a page that uses Collapse, expect to replace it with a host-level header plus an ordinary conditional body rather than to patch around it.

Rust
›
Replicas3
Replicas3

Sizing, timing and the stylesheet

max-height is the animation channel and it is hard-coded at 1000px when open — content taller than that is clipped, and content much shorter than that spends most of the transition invisible because the height is animating across the full 1000px while the opacity ramp is doing the visible work. duration moves both the height and the opacity transition and the chevron rotation; there is no easing prop (the inline styles use ease-in-out).

Two stylesheets exist and their numbers differ: the component's own CollapseComponent::styles() writes a 0.5rem row padding and a small arrow with a 0.2s rotation, while the registry sheet the crate actually imports (styles/components/collapse.scss, through styles/index.scss) writes 8px 12px padding, a 16px arrow with a hover wash and the same 0.2s. The class list says more than the sheets use: the component emits hk-collapse-collapsed for the closed state and hk-collapse-expanded for the open one, but neither sheet has a rule for the collapsed class — the closed look comes entirely from the shared .hk-collapse-content { max-height: 0; opacity: 0 } base rule, so the two state classes are not symmetric and only the open one changes anything. class is appended to the outer hk-collapse only (it renders as hk-collapse <class>, with a literal space even when empty), so a host skin has to reach in through a descendant selector.

Rust
›Instant fold
Instant fold
›No transition
No transition
›Slow fold
Slow fold

API

Rust

Props — Collapse

PropTypeDefaultDescription
expandedboolfalse—
durationu64200—
animatedbooltrue—
classString""—
childrenElement(empty)—
on_expandOption<EventHandler<bool>>None—

Accessibility

  • The header is a div, not a <button> and not a <summary>: it is not focusable, it has no role, and it is not operable from the keyboard at all. The only way to fold a group is a pointer press.
  • Nothing announces the open state. There is no aria-expanded, no aria-controls, and the chevron is a text › in a plain span with no label, so a screen reader moving through the page cannot tell which groups are open, and the rotated glyph is read as a stray punctuation character.
  • The content is not hidden when closed in the accessibility tree — it is only given max-height: 0 and opacity: 0 by CSS, both of which keep it in the DOM and therefore in the reading order. A closed group's content is still announced (twice, per the duplication above), and any focusable control inside it is still reachable by Tab even though it is invisible. That is a genuine defect, not a trade-off.
  • Because the children render in the header too, a closed group announces its body text as the header label.
  • A group with duration: 0 or animated: false is still a pointer-only control: the missing keyboard path is not a timing issue.

Related components

  • TreeNode — the legacy node with its own arrow; the same disclosure idea, applied to rows.
  • JsonTree — the supported folding viewer, with a real role="tree" root.
  • Tree — the supported tree, which owns opening and closing without a separate disclosure component.
  • DragDropTree — the other legacy tree surface in this group.