A navigation tree of workspaces, teams and pages.
- 12.9 kB JS 4.6 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- 5 keys checked
- Right-to-left, arrows swap
- 19 tests
When to use
A navigation tree of workspaces, teams and pages. Use Page Tree instead when the sidebar lists a workspace's documents.
Usage
import { Nav } from "./ui/uicontext/components/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, RequestedExpand: () => undefined, RequestedCollapse: () => undefined, }, })API reference
Props
| Name | Type | Description |
|---|---|---|
labelrequired | string | The navigation's accessible name: "Workspace" |
sectionsrequired | NavSection[] | The sidebar's sections, each a titled tree of items |
current | string | null | The item for the page shown now |
expanded | string[] | Items open at first (the current item's parents always are) |
closed | string[] | Sections closed at first |
agentId | string | This navigation's id for agents, unique on the page |
Events
| Event | Payload | Description |
|---|---|---|
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. |
RequestedExpand | { id: string; link: string } | Opened: load its children (for link) if they aren't there yet |
RequestedCollapse | { id: string; link: string } | An item was closed |
Agent actions
| Action | Description |
|---|---|
ActivatedItem | Open an item by its id (see page_query for every item) |
ToggledItem | Open or close an item's children |
ClickedSection | Open or close a section |
ClickedSectionAdd | Add to a section (its add button) |
ClickedItemAction | Run one of an item's actions, by item id and action id |
MovedItem | Move 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 |
Keyboard and accessibility
| Keys | Does |
|---|---|
| ↓Down arrow ↑Up arrow | Move between links |
| →Right arrow | Open a section, or move into it |
| ←Left arrow | Close it, or move to the parent |
| HomeHome EndEnd | Go to the first or the last link |
| EnterEnter | Follow the link |
- A
navlandmark 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.