Skip to content

HySidebar

Usage examples on this page are written for Lit / plain HTML (<hy-sidebar>). The same component ships as HySidebar in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

A persistent navigation rail with collapse-to-icon-only state.

hy-sidebar is a single <nav> landmark — it does not wrap in <aside>, because <aside> is itself a complementary landmark and nesting the two would expose two landmarks for one purpose.

Pair with hy-sidebar-group for titled sections and hy-sidebar-item for rows. On mobile, wrap the sidebar inside hy-drawer — the drawer provides overlay/focus-trap semantics, the sidebar provides the content.

Examples

html
<hy-sidebar label="Main navigation">
  <div slot="header">Edelweiss</div>
  <hy-sidebar-group label="Workspace">
    <hy-sidebar-item value="dashboard" href="/dashboard" active>
      <hy-icon slot="leading" name="home" decorative></hy-icon>
      Dashboard
    </hy-sidebar-item>
    <hy-sidebar-item value="projects" href="/projects">
      <hy-icon slot="leading" name="folder" decorative></hy-icon>
      Projects
    </hy-sidebar-item>
  </hy-sidebar-group>
  <hy-sidebar-group label="Settings">
    <hy-sidebar-item value="preferences" href="/preferences">
      <hy-icon slot="leading" name="cog" decorative></hy-icon>
      Preferences
    </hy-sidebar-item>
  </hy-sidebar-group>
</hy-sidebar>

Collapsible rail with the built-in toggle

html
<hy-sidebar collapsible toggle-placement="header-end" width-expanded="280px">
  <div slot="header">Edelweiss</div>
  <hy-sidebar-item value="home" href="/">
    <hy-icon slot="leading" name="home" decorative></hy-icon>
    Home
  </hy-sidebar-item>
</hy-sidebar>
<script>
  document.querySelector('hy-sidebar').addEventListener('collapse', (e) => {
    console.log(e.detail.collapsed);
  });
</script>

API

Properties

PropertyAttributeTypeDefaultDescription
collapsedcollapsedbooleanfalseWhether the sidebar is collapsed to icon-only mode.
collapsiblecollapsiblebooleanfalseWhether to render a built-in collapse toggle at the top of the sidebar. The toggle is an hy-icon-button so its hit-area, hover/focus styling and theming follow the same scale as every other icon-button in the system (32px at size="small"). The icon name is hard-coded to arrow-collapse so consumers can't accidentally pass an undefined value — the historical foot-gun this slot was designed to avoid.
placementplacement'start' | 'end''start'Which edge of the parent the sidebar sits on.
togglePlacementtoggle-placement'top-corner' | 'header-end''top-corner'Where the built-in collapse toggle is placed. See SidebarTogglePlacement for the visual contract of each value. Default top-corner preserves pre-existing behavior; pick header-end when the brand mark is the visual anchor and the toggle should sit below it (Material 3 / modern SaaS pattern).
labellabelstring'Main navigation'Accessible label for the <nav> landmark.
collapseLabelcollapse-labelstring'Collapse'Label on the collapse toggle when the sidebar is expanded.
expandLabelexpand-labelstring'Expand'Label on the collapse toggle when the sidebar is collapsed.
widthExpandedwidth-expandedstring''Width when expanded. Escape hatch; writes --hy-sidebar-width-expanded inline.
widthCollapsedwidth-collapsedstring''Width when collapsed. Escape hatch; writes --hy-sidebar-width-collapsed inline.

Events

EventDetailDescription
collapseFired on every collapse state change. Detail: { collapsed: boolean }

Slots

SlotDescription
headerLogo, brand, or title above the nav. Stays visible when collapsed. Slot icon-only content (≈32px) that reads in the narrow rail. Position relative to the collapse toggle depends on togglePlacement — see that property for the visual contract.
defaultItems and groups.
footerAccount, settings, version badge. Hidden chrome when empty.

CSS Parts

PartDescription
baseThe <nav> landmark.
headerHeader region.
contentScrollable middle region containing items/groups.
footerFooter region.
collapse-toggleThe built-in collapse toggle button (only rendered when collapsible).

CSS Custom Properties

PropertyDescription
--hy-sidebar-width-expandedWidth when expanded (default: 260px)
--hy-sidebar-width-collapsedWidth when collapsed (default: 64px)
--hy-sidebar-backgroundBackground color (default: surface-base)
--hy-sidebar-border-colorBorder color (default: border-default-rest)
--hy-sidebar-padding-blockBlock padding for header/content/footer
--hy-sidebar-padding-inlineInline padding for header/content/footer
--hy-sidebar-gapGap between items at the root
--hy-sidebar-transition-durationCollapse transition duration
--hy-sidebar-control-insetDistance from the top + inline-end corner to the absolute-positioned collapse toggle (default: padding-sm)
--hy-sidebar-collapsedHost-scope variable exposing 1 (collapsed) or 0 (expanded) for descendant / consumer styling (read it via var(); nothing in Harmony consumes it yet)
--hy-sidebar-transition-easingEasing for the collapse and expand transition

Methods

expand()

Expand the sidebar. No-op if already expanded.

collapse()

Collapse the sidebar. No-op if already collapsed.

toggle()

Toggle the collapsed state.

Built with Lit. Documented with VitePress.