Skip to content

HySidebarItem ​

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

Used inside <hy-sidebar> — it only means something as part of it.

A single row inside an hy-sidebar — icon, label, optional trailing content.

Renders as <a> when href is set and not disabled, otherwise <button>. disabled always wins — a disabled item is a <button disabled> regardless of href, because HTML has no native disabled attribute on anchors.

When the parent hy-sidebar is collapsed, the label hides visually but the accessible name survives via aria-label, and a tooltip mounts around the row using the same label text.

When not to use

  • An action that changes something without going to another page: hy-button, not a sidebar row.

Examples ​

html
<hy-sidebar-item label="Dashboard" value="dashboard" href="/dashboard" active>
  <hy-icon slot="leading" name="home" decorative></hy-icon>
</hy-sidebar-item>

Button row with trailing content and client-side routing ​

html
<hy-sidebar-item label="Inbox" value="inbox" href="/inbox">
  <hy-icon slot="leading" name="folder" decorative></hy-icon>
  <span slot="trailing">12</span>
</hy-sidebar-item>
<script>
  document.querySelector('hy-sidebar-item').addEventListener('activate', (e) => {
    e.detail.originalEvent.preventDefault(); // intercept, then route client-side
    console.log(e.detail.value, e.detail.href);
  });
</script>
html
<hy-sidebar-item
  label="Primitives"
  variant="section"
  value="primitives"
  href="/tokens/primitives"
  active
  aria-expanded="true"
>
  <hy-icon slot="leading" name="chevron-down" decorative></hy-icon>
</hy-sidebar-item>

API ​

Properties ​

PropertyAttributeTypeDefaultDescription
valuevaluestring''Identifier emitted in the activate event.
hrefhrefstring''When set (and not disabled), the row renders as an <a>.
targettargetstring''Anchor target; paired with href.
activeactivebooleanfalseActive state. Sets aria-current on the row (value from current).
currentcurrent'page' | 'true''page'The aria-current value an active row announces. Leave at page for a row whose href is the current URL; set true when the row is an in-page selection, so two rows in one nav never both claim page.
disableddisabledbooleanfalseDisabled state. Forces <button disabled> regardless of href.
labellabelstring''The row's text — the name of the page it leads to; the tooltip and aria-label of a collapsed row.
sizesize'small' | 'medium''medium'Density variant. small tightens padding and shifts typography down one step — matching hy-link size="small" for navigation-dense sidebars (docs TOC etc). Neither size has a height floor with a fine pointer; both floor at the small touch target on a coarse one.
variantvariant'default' | 'section''default'section makes the row the head of a section of the nav — a link to the section that also opens its list (with aria-expanded), the Spectrum multilevel side-nav shape. The current one is marked by its brand ink instead of the selection fill, it hovers like its siblings, and its leading box fits a chevron (put an hy-icon name="chevron-down" in leading). Its text keeps the item's type; a consumer that wants the row in a heading style sets the font hooks. default is the ordinary row.
ariaExpandedaria-expanded'true' | 'false'nullThe row also discloses something — a section row whose list it folds. 'true' / 'false' is forwarded as aria-expanded on the inner link or button (a link may carry it: it still navigates, and says whether what it opens is open); null (default) for a plain row. As hy-link's.

Events ​

EventDetailDescription
activate—Fired on click (before navigation). Consumers with client-side routing can detail.originalEvent.preventDefault() to intercept. Detail: { value, href, originalEvent }

Slots ​

SlotDescription
leadingOptional icon. Reserved layout column only when content is present, or when the parent sidebar is collapsed (where the glyph is essentially required).
trailingBadge, count, or chevron. Column is hidden when the slot is empty.

CSS Parts ​

PartDescription
baseThe interactive <a> or <button> element.
leadingLeading slot wrapper.
labelLabel wrapper.
trailingTrailing slot wrapper.

CSS Custom Properties ​

The documented hooks. Every override hook the component reads — one per token it paints — is listed in @whitespaceux/harmony/theme-api.json, and @whitespaceux/harmony/component-bindings.json (the Harmony MCP get-bindings tool) says which part and state each one paints.

PropertyDefaultDescription
--hy-sidebar-item-gap-row-nav-md-inlinevar(--hy-gap-row-nav-md-inline)Gap between leading/label/trailing
--hy-sidebar-item-gap-row-nav-xs-inlinevar(--hy-gap-row-nav-xs-inline)Gap between leading/label/trailing
--hy-sidebar-item-padding-row-nav-sm-blockvar(--hy-padding-row-nav-sm-block)Block padding
--hy-sidebar-item-padding-row-nav-xs-blockvar(--hy-padding-row-nav-xs-block)Block padding
--hy-sidebar-item-padding-row-nav-sm-inlinevar(--hy-padding-row-nav-sm-inline)Inline padding (both sizes)
--hy-sidebar-item-radius-row-nav-smvar(--hy-radius-row-nav-sm)Border radius
--hy-sidebar-item-icon-size—Leading/trailing icon size (default: 20px at medium, 16px at small)
--hy-sidebar-item-icon-size-xsvar(--hy-icon-size-xs)Leading/trailing icon size of a section row (the chevron's box)
--hy-sidebar-item-body-md-font-familyvar(--hy-body-md-font-family)Label font family (default: the size's label family)
--hy-sidebar-item-body-sm-font-familyvar(--hy-body-sm-font-family)Label font family (default: the size's label family)
--hy-sidebar-item-body-md-font-sizevar(--hy-body-md-font-size)Label font size (default: the size's label size)
--hy-sidebar-item-body-sm-font-sizevar(--hy-body-sm-font-size)Label font size (default: the size's label size)
--hy-sidebar-item-body-md-font-weightvar(--hy-body-md-font-weight)Label font weight (default: the size's label weight)
--hy-sidebar-item-body-sm-font-weightvar(--hy-body-sm-font-weight)Label font weight (default: the size's label weight)
--hy-sidebar-item-body-md-line-heightvar(--hy-body-md-line-height)Label line height (default: the size's label line height)
--hy-sidebar-item-body-sm-line-heightvar(--hy-body-sm-line-height)Label line height (default: the size's label line height)
--hy-sidebar-item-body-md-letter-spacingvar(--hy-body-md-letter-spacing)Label letter spacing (default: the size's label letter spacing)
--hy-sidebar-item-body-sm-letter-spacingvar(--hy-body-sm-letter-spacing)Label letter spacing (default: the size's label letter spacing)
--hy-sidebar-item-background-resttransparentBackground at rest
--hy-sidebar-item-background-neutral-hovervar(--hy-background-neutral-hover)Background on hover
--hy-sidebar-item-background-selection-restvar(--hy-background-selection-rest)Background when active
--hy-sidebar-item-background-selection-hovervar(--hy-background-selection-hover)Background on hover when active
--hy-sidebar-item-foreground-default-restvar(--hy-foreground-default-rest)Text color at rest and when active
--hy-sidebar-item-foreground-brand-restvar(--hy-foreground-brand-rest)Text color of the current section row
--hy-sidebar-item-foreground-default-hovervar(--hy-foreground-default-hover)Text color on hover
--hy-sidebar-item-foreground-icon-default-disabledvar(--hy-foreground-icon-default-disabled)The slotted icons' color when the row is disabled
--hy-sidebar-item-motion-transition-hover-durationvar(--hy-motion-transition-hover-duration)Transition duration for hover and focus state feedback
--hy-sidebar-item-motion-transition-hover-easingvar(--hy-motion-transition-hover-easing)Transition easing for hover and focus state feedback

Methods ​

focus() ​

Programmatically focus the underlying interactive element.

Built with Lit. Documented with VitePress.