Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

App Nav

PreviousNext

Renders a navigation model into the Sidebar, with groups, badges, statuses, children, row actions, reordering, pinning and hiding.

App Nav turns a plain list of groups and items into Sidebar rows. The list is data from lib/app-shell-model.ts, so the same config can drive a web sidebar and a native app's drawer, and route matching lives in one place.

Everything a person changes (the order, what is pinned or hidden, which groups are open) comes back as one serializable value, preferences, for you to store where you like.

App Nav is part of the Fabricator style.

Installation

bunx --bun fabricator-ui@latest add app-nav

Usage

import { AppNav, type AppNavGroup } from "@/components/ui/app-nav"
const groups: AppNavGroup[] = [
  {
    id: "main",
    items: [
      { id: "home", label: "Home", href: "/", icon: HomeIcon },
      { id: "inbox", label: "Inbox", href: "/inbox", icon: InboxIcon, badge: 3 },
    ],
  },
  {
    id: "projects",
    label: "Projects",
    collapsible: true,
    reorderable: true,
    items: projects.map((project) => ({
      id: project.id,
      label: project.name,
      href: `/projects/${project.id}`,
      actions: [{ id: "rename", label: "Rename", onSelect: () => rename(project) }],
    })),
  },
]
 
<SidebarContent>
  <AppNav groups={groups} pathname={pathname} renderLink={(item) => <Link href={item.href ?? "/"} />} />
</SidebarContent>

The model

Field (item)What it does
hrefThe row links to it. Items with children and no href toggle instead.
matchexact: true matches only the item's own path; prefixes adds paths it owns.
iconA component, shown in the row and in the collapsed rail.
badgeA count or a short label on the row's trailing edge.
statusactive and unread draw a filled dot, idle a ring.
childrenItems under this one, nested to any depth; the sub-tree opens on its own when it holds the current page.
actionsThe row's menu entries ({ id, label, icon?, shortcut?, destructive?, separatorBefore?, onSelect }).
mobile"tab" puts the item in AppNavBottomBar on phones.

Groups take label, collapsible, defaultOpen, reorderable and actions (shown as buttons in the group's header).

The current page decides the active item: the item whose href or prefixes match the longest part of pathname wins. Pass activeId to set it yourself.

Nesting

children nest to any depth. Each level sits 16px further in, with 14px icons and muted labels; a hairline under the parent's icon shows while you point at the list.

  • Opening. A row with children swaps its icon for a chevron while it is hovered or focused (always on touch, and when it has no icon). The chevron opens and closes the row; the row itself still goes to its page. A row without an href opens and closes on click. Open rows are remembered in preferences.open.
  • The current page. Its top-level row is raised, as the page's own row is when it sits at the top; a nested page's row sits on a quieter wash.
  • Icons. A row without an icon keeps the icon column when a sibling has one, so labels line up.

getNavPath(groups, id) in the model returns an item and its ancestors, for breadcrumbs.

Examples

In an App Shell

With a Workspace Switcher above and a User Menu below.

Reordering

Rows in a reorderable group drag to a new place in their list: top-level rows within the group, children among their siblings at any depth. From the keyboard, focus a row and press ⌥⇧↑ or ⌥⇧↓; every row's menu also has Move up and Move down, and a top-level row's has Move to, which sends it to another reorderable group. Moves are announced.

The new order is saved in preferences.order, by group id for top-level rows and by item id for children. When your items change, saved orders adapt: unknown ids are dropped and new items appear after the saved ones.

Customizing

customizable adds Pin to top and Hide to every row's menu. Pinned items show in a group at the top (pinnedLabel, "Pinned" by default). AppNavCustomize opens a dialog that lists every item in its saved order, with a grip to reorder it and a switch to show or hide it, and a Reset button. Reordering there works in any group, reorderable or not; focus a grip and press ↑ or ↓ to do it from the keyboard:

const [preferences, setPreferences] = React.useState(EMPTY_NAV_PREFERENCES)
 
<AppNav groups={groups} preferences={preferences} onPreferencesChange={setPreferences} customizable />
<SidebarFooter>
  <AppNavCustomize groups={groups} preferences={preferences} onPreferencesChange={setPreferences} />
</SidebarFooter>

Store preferences per person (a database, localStorage, the App Shell storage) and restore it with parseNavPreferences, which drops anything malformed.

On phones

Below 768px the Sidebar sits behind the page in an App Shell (a sheet elsewhere), and App Nav closes it after a row is picked. For a bottom nav, mark items mobile: "tab" and render AppNavBottomBar in the main column:

<AppShellMain>
  …
  <AppNavBottomBar
    groups={groups}
    pathname={pathname}
    renderLink={renderLink}
  />
</AppShellMain>

API Reference

AppNav

Also takes the props of a <nav>.

PropTypeDefault
groupsAppNavGroup[]-
pathnamestring""
activeIdstring | nullfrom pathname
preferencesNavPreferences-
defaultPreferencesNavPreferencesempty
onPreferencesChange(preferences: NavPreferences) => void-
renderLink(item) => React.ReactElementan <a>
onNavigate(item) => void-
customizablebooleanfalse
pinnedLabelstring"Pinned"
aria-labelstring"Main"

AppNavCustomize

PropTypeDefault
groupsAppNavGroup[]-
preferencesNavPreferences-
onPreferencesChange(preferences: NavPreferences) => void-
childrenthe trigger elementa sidebar row
labelstring"Customize"
titlestring"Customize sidebar"

AppNavBottomBar

PropTypeDefault
groupsAppNavGroup[]-
pathnamestring""
activeIdstring | nullfrom pathname
renderLink(item) => React.ReactElementan <a>

Accessibility

  • App Nav is a nav landmark labelled "Main". The current page's row has aria-current="page"; the raised top-level row above a nested page doesn't.
  • Rows with children have aria-expanded, on the row when it only toggles and on its chevron button when it links; collapsible group labels are buttons.
  • ↑ and ↓ move between visible rows at every depth. → opens a row, ← closes it, and ← on a closed row moves to its parent.
  • Each row's actions are in a menu reachable from its ⋯ button and from the context menu key.
  • Every drag has keyboard and menu alternatives, and moves are announced in a live region (WCAG 2.5.7).
  • In the collapsed rail, each row's tooltip names it.