MenuSection
HkMenuSection is a captioned run of menu rows: a small caption above its rows, wrapped in a role="group" box named by label. The caption is one band of the library's unified menu-item grammar (bottom-heavy rhythm, so the caption reads as the head of the rows below rather than as one of them), and this component is the one markup for it — the same caption used to be hand-rolled at every call site with its own insets.
- The rows inside are whatever the host writes: MenuActionItem rows, navigation rows, hand-built buttons. The section only groups them and captions them.
- The caption is the group's accessible name, so it follows the standard grouping rules: the group announces the name and the visible band is hidden from assistive technology, leaving one announcement per group instead of two.
- The identity row above a user menu is MenuIdentityItem; an interactive navigation row is NavItem.
Import
;
use *; // MenuSection, menu_section_caption_visible
use *; // MenuSectionProps, rsx!, VNode
The Rust form is a plain function, MenuSection(MenuSectionProps { … }), and MenuSectionProps is in the prelude. Vue's label is label there too, the #label slot is caption: Option<Element> (Some(rsx! { … })), and the default slot is children.
label is required in Vue; the Rust struct is Default-constructible, so the requirement is documented on the field instead of enforced — an omitted label renders an empty caption and an empty aria-label, which is exactly the unnamed group the component exists to prevent.
The wrapper carries no chrome of its own — the caption owns the band. This component also ships no stylesheet of its own: HkMenuSection.tsx imports no scss, and the two class names (.hk-menu-section, .hk-menu-section-label) are bound to the menu-item grammar by the library's global admin-token rules, so a host that renders the same classes by hand and this component share one declaration. The Rust mirror follows the same rule and registers no sheet of its own (a second copy would emit the rules twice).
The caption, and the slot that overrides it
label does two jobs at once: it is the group's accessible name (aria-label on the role="group" wrapper) and the default visible caption text. The #label slot (caption in Rust) replaces the visible text only — a count, a badge, richer markup — while aria-label keeps the plain string from the prop.
The slot is only honoured when it carries something visible. Blank text, whitespace-only strings, an empty fragment or a fragment made only of comments all fall back to the prop text, so a conditional caption never leaves a padded, empty aria-hidden band. Vue makes that decision with hasVisibleContent inside the render function (not a cached computed, whose vnodes would go stale on a parent re-render); Rust ports the same walk as menu_section_caption_visible, minus the comment-node case — the Rust vdom has no comment nodes, so that branch cannot occur there.
The Rust crate has no mirror of MenuActionItem, so the Rust example writes rows carrying the grammar's class by hand — which is exactly the case the grammar is designed for: a host that renders these classes itself and the component then share one declaration. The component's own stylesheet is deliberately empty for the same reason; a second copy of the same rules would double them.
A caption with more than text
The slot's whole purpose is a caption the prop cannot express — "Spaces" plus a count, or a name plus a badge. Two rules come with it: the content must be non-interactive (it renders inside the aria-hidden band, so a focusable node there is an aria-hidden-focus violation), and its visible text must not contradict the prop, which is still what assistive technology announces.
Where the rhythm comes from
The wrapper is a flex column whose gap mirrors the parent menu's own row rhythm — 2px by default, and the panel class the menu itself uses publishes 4px. Two stacked sections take a 6px stack margin so two captioned runs read as two groups instead of one long list. Nothing here has horizontal padding: the surface's own inset is the one inset the rows receive, and the caption's inline inset is deliberately a hair smaller than the row's, so it hangs just left of the rows' icon column.
If your list separates rows with margins instead of a gap, set the section's gap token to 0 and keep your margins; they still apply inside the wrapper.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| label | String | — | ✓ |
Rust
Props — MenuSection
| Prop | Type | Default | Description |
|---|---|---|---|
| label | String | "" | Accessible group name AND the default visible caption text (Vue: label, REQUIRED — a Rust props struct is Default-constructible, so the required-ness is documented rather than enforced). |
| caption | Option<Element> | None | Richer visible caption content — a badge, a count (Vue: the #label slot). |
| children | Element | (empty) | The captioned rows (Vue: the default slot). |
Accessibility
- The wrapper is a div with role="group" and aria-label equal to label, so assistive technology announces the group name before its rows and the grouping survives even though the box draws nothing but a caption.
- The visible caption band is aria-hidden="true". That is deliberate — the group already announces the name, so leaving the band in the accessibility tree would read the caption twice — and it is why the #label slot must not hold anything focusable: a focusable node inside an aria-hidden subtree is an aria-hidden-focus violation.
- The caption carries no text-transform. Translators own casing, and a slot that renders "spaces" where the prop says "Spaces" is a mismatch between what is seen and what is announced.
- The section is not a list: its rows are not role="option" or role="menuitem" by virtue of being inside it, and no aria-activedescendant is written. Row semantics come from the rows themselves, and menu-level keyboard handling comes from the menu container.
- In Rust the same structure is emitted, but with one fewer case: the vdom has no comment nodes, so a caption that in Vue compiles to a comment vnode (an empty v-if root) cannot be produced — the remaining visibility rules (blank text, empty or nested fragments, any element) port verbatim.
Related components
- MenuActionItem — the rows this section captions.
- MenuIdentityItem — the identity block that usually sits above the first section.
- NavItem — the navigation row, when the run of rows belongs to a sidebar rather than a popup menu.
- NavSidebar — a whole navigation band, when the grouping is the app's own navigation rather than menu sections.