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.

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.

Examples

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

Button row with trailing content and client-side routing

html
<hy-sidebar-item value="inbox" href="/inbox">
  <hy-icon slot="leading" name="folder" decorative></hy-icon>
  Inbox
  <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>

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="page" on the <a>.
disableddisabledbooleanfalseDisabled state. Forces <button disabled> regardless of href.
labellabelstring''Explicit accessible name. Overrides the auto-derived text from the default slot. Useful for i18n or when the visible label is not suitable for screen readers.
sizesize'small' | 'medium''medium'Density variant. small tightens padding, drops the minimum 40px touch-target floor, and shifts typography down one step — matching hy-link size="small" for navigation-dense sidebars (docs TOC etc).

Events

EventDetailDescription
activateFired 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).
defaultLabel text.
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

PropertyDescription
--hy-sidebar-item-gapGap between leading/label/trailing
--hy-sidebar-item-padding-blockBlock padding
--hy-sidebar-item-padding-inlineInline padding
--hy-sidebar-item-radiusBorder radius
--hy-sidebar-item-icon-sizeLeading/trailing icon size (default: 20px at medium, 16px at small)
--hy-sidebar-item-min-block-sizeMinimum row height (default: touch target at medium, auto at small)
--hy-sidebar-item-background-restBackground at rest
--hy-sidebar-item-background-hoverBackground on hover
--hy-sidebar-item-background-activeBackground when active
--hy-sidebar-item-foreground-restText color at rest
--hy-sidebar-item-foreground-hoverText color on hover
--hy-sidebar-item-foreground-activeText color when active
--hy-sidebar-item-hover-durationTransition duration for hover and focus state feedback
--hy-sidebar-item-hover-easingTransition easing for hover and focus state feedback

Methods

focus()

Programmatically focus the underlying interactive element.

Built with Lit. Documented with VitePress.