Sidebar

A navigation tree of workspaces, teams and pages.

Alt+arrows move a page; drag one onto another to nest it.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/nav

Usage

import { Nav } from "./ui/uicontext/components/kit/Nav.ts"
const Message = UiSchema.TaggedEnum({ RequestedOpenPage: { id: Schema.String } })export const Sidebar = (h: Html.H<typeof Message.Type>, current: string) =>	Nav(h, {		props: {			label: "Workspace",			current,			sections: [				{					id: "teams",					title: "Your teams",					items: [						{ id: "engineering", label: "Engineering", href: "/engineering" },						{ id: "issues", label: "Issues", href: "/engineering/issues", parent: "engineering", count: 12 },					],				},			],		},		onEmit: {			RequestedOpen: ({ id }) => Message.RequestedOpenPage({ id }),			RequestedAction: () => undefined,			RequestedMove: () => undefined,			RequestedAdd: () => undefined,			Expanded: () => undefined,			Collapsed: () => undefined,		},	})

API reference

Props

Nav props
NameTypeDescription
labelrequiredstringThe navigation's accessible name: "Workspace"
sectionsrequiredNavSection[]The sidebar's sections, each a titled tree of items
currentstring | nullThe item for the page shown now
expandedstring[]Items open at first (the current item's parents always are)
closedstring[]Sections closed at first
agentIdstringThis navigation's id for agents, unique on the page

Events

Nav events
EventPayloadDescription
RequestedOpen{ id: string; link: string }An item without a link was activated, or an agent opened one
RequestedAction{ id: string; action: string; link: string }An action from an item's menu was chosen: the app does it
RequestedAdd{ section: string }A section's add button was pressed: the app creates an item there
RequestedMove{ id: string; link: string; into: string | null; section: string; before?: string | null }into an item (or null: the section's top level). before is set only in a reorderable section: the sibling (an item id) it goes before, or null for last. Without it, the app picks the place.
Expanded{ id: string; link: string }Opened: load its children (for link) if they aren't there yet
Collapsed{ id: string; link: string }An item was closed

Agent actions

What agents can do with Nav
ActionDescription
ActivatedItemOpen an item by its id (see page_query for every item)
ToggledItemOpen or close an item's children
ClickedSectionOpen or close a section
ClickedSectionAddAdd to a section (its add button)
ClickedItemActionRun one of an item's actions, by item id and action id
MovedItemMove an item into another (into: its id) or to its section's top level (into: null). In a reorderable section, before: the sibling it goes before there, or null for last

Accessibility

  • A nav landmark whose sections are each a WAI-ARIA tree and one Tab stop: Up and Down move, Right opens or moves in, Left closes or moves out, Home and End jump, and typing jumps to an item.
  • Enter follows the link, and the current page is aria-current="page". Shift+F10 opens an item's actions; Alt with the arrow keys moves a movable item.
  • Counts and attention dots are read as words. Agents read the visible items and open one by id.

Source