NavItem

NavItem

HkNavItem is one row of a navigation list — and it picks its element from what the row is: a <button> for an in-page action, an <a> for a destination, or an accordion group whose children are fragment links. All three branches share one row grammar (metric tokens from the library's menu-item sheet), so a sidebar made of these rows keeps a single height, icon cell and hover wash whatever each row links to.

  • A row is one destination or one group. The band that stacks rows into an app sidebar, sets the active route for you and emits a navigate event is NavSidebar.
  • The scrollable panel a stack of rows lives in is Sidebar; this page covers the row only.
  • The trailing chevron is the library icon set's right chevron and rotates a quarter turn when a group opens; the group control is the row itself, not a separate disclosure button.

Import

tsx
1
import { HkNavItem } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // NavItem, NavItemChild, NavItemKind
use hikari_components::prelude::*; // rsx!, VNode, Icon, MdiIcon, EventHandler, MouseEvent

The Rust form is a plain function, NavItem(NavItemProps { … }). Inside rsx! every prop may be omitted. The mirror renames Vue's children array prop to sub_items — children keeps its slot meaning (Vue's default slot) — and it moves two pieces of Vue-internal state onto props, which is the subject of the third section below.

Which element a row renders

The branch is decided in a fixed order: a non-empty child-row list wins over to, to wins over href, and a row with none of them is a plain button. The branch matters beyond markup:

  • the to branch carries aria-current="page" while active, the href branch does not;
  • both anchor branches emit click, and a disabled anchor keeps its href shape but is dimmed and swallows the press (aria-disabled plus the stylesheet's gate), whereas a disabled button carries the native disabled attribute and is therefore skipped by the Tab order;
  • the group branch renders a wrapper div around its button, and the children only exist while the group is open.

Every to / href goes through the library's URL allowlist (http:, https:, mailto:, tel:, /-rooted paths, # fragments and ./ / ../ pass; anything else becomes the inert "#"). Child rows are the exception: they always link to #<child.id> on the same document, because a fragment cannot carry a scheme.

OverviewDocs

The icon and label slots

The row's content is two slots, each wrapped in its own span only when it carries something: icon for the leading glyph and default for the label. The stylesheet owns the icon cell (16px) and ellipsizes the label, so a long name truncates rather than widening the row.

A child row has a third cell of its own: badge, a small pill pushed to the inline end. The badge exists only on child rows — Vue's NavItemChild is the only place it is read — so a top-level row that needs a count puts it in the label slot instead.

In the Rust mirror the icon is a typed MdiIcon rather than a component, and icon_slot: Some(empty_vnode()) deliberately keeps an empty icon cell, which is how Vue's slot-presence test behaves when the slot function returns nothing.

The accordion group, and the two ways to drive it

In Vue the open state of an accordion group is private: the component holds an expanded ref that starts closed, the group's button flips it, and the child rows appear inside the group. Nothing outside can read the state, and no event reports the flip — the button press never reaches the click emit either (the group's own handler runs instead of the row handler). A host that must know whether a group is open therefore cannot get it from this component in Vue; it re-renders the group with its own child list, or uses its own accordion markup.

The Rust mirror cannot keep that state inside the component — the framework's component-body hooks are render-scoped — so it exposes the flag as a controlled prop: expanded says whether the group renders open, and a press calls on_toggle with the value it would take (!expanded). The host stores the flag and passes it back. Two further mirror deltas follow from the same constraint: Vue tests the child array's presence, so an empty [] still renders the accordion shell, while the mirror tests emptiness (a Rust Vec cannot tell "absent" from "empty"); and the arrow glyph is the library icon's markup mounted on a paint-inert host, which is a rendering detail rather than a behavioural one.

Because the mirror owns no state, a NavItem with sub_items and expanded: false renders the collapsed shell and no children in the snapshot below — the chevron is the only visible difference between the two rows until a host flips the flag.

API

Vue

Props

NameTypeDefaultRequired
activeBooleanfalse—
disabledBooleanfalse—
toStringundefined—
hrefStringundefined—
childrenArray as PropType<NavItemChild[]>undefined—

Emits

EventPayload
clickMouseEvent

Rust

Props — NavItem

PropTypeDefaultDescription
activeboolfalseVue: active (the row is the current route).
disabledboolfalseVue: disabled.
toOption<String>NoneVue: to — the route target; renders an anchor that also carries aria-current="page" while active.
hrefOption<String>NoneVue: href — a link target without aria-current.
sub_itemsVec<NavItemChild>[]Vue: the children ARRAY prop — the child rows of the accordion branch (see the header delta on the rename).
expandedboolfalseThe accordion flag (Vue: the local expanded ref); controlled here.
icon_slotOption<Element>NoneThe icon slot (Vue: slots.icon).
childrenElement(empty)The default slot (Vue: slots.default, the row label).
onclickOption<EventHandler<MouseEvent>>NoneThe click emit (Vue: emits: { click }).
on_toggleOption<EventHandler<bool>>NoneThe accordion toggle; it fires with the NEW value (Vue's group button flips its own ref instead of emitting).
classString""Fallthrough host class (Vue: the class attr merge on the branch root).

Accessibility

  • The element follows the row's job, so the native semantics come for free: a button is pressed with Enter or Space, a link is followed with Enter, and the disabled state reaches assistive technology through disabled (button) or aria-disabled (anchor).
  • active on a to row adds aria-current="page". The same active on an href row or a plain button only changes the visuals — those branches have no current-page semantics — so a row that marks the current location should be built with to.
  • The group's button is a <button type="button"> labelled by its label slot, and the chevron is rotated by a class rather than announced; the button carries no aria-expanded in either form, so the open/closed state of an accordion group is visual only today.
  • The focus ring is drawn inside the row's own box (outline-offset: -2px), which keeps it visible for child rows that sit inside the indented children block.
  • A disabled anchor is still in the Tab order even though it cannot be followed; a disabled button is not. Pick the branch deliberately when a row is unavailable rather than unreachable.

Related components

  • NavSidebar — the ready-made band of these rows, with route matching and a navigate event.
  • Sidebar — the scrollable panel that holds a stack of rows, with an optional icon rail.
  • Breadcrumb — the horizontal trail, for hierarchy above the page rather than navigation inside it.
  • SidebarRailToggle — the circular control that collapses a panel of rows to its icon rail.