# Navigation

TabNav, Breadcrumb, NavList, Tree and Tabs: where the reader is, and how they get somewhere else, drawn the same way in every app.

API [TabNav](/ui/storybook/?path=/docs/ui-primitives-tabnav--docs) [Breadcrumb](/ui/storybook/?path=/docs/ui-primitives-breadcrumb--docs) [NavList](/ui/storybook/?path=/docs/ui-primitives-navlist--docs) [Tree](/ui/storybook/?path=/docs/ui-primitives-tree--docs) [FileTree](/ui/storybook/?path=/docs/ui-filetree--docs) [Tabs](/ui/storybook/?path=/docs/ui-primitives-tabs--docs) [LinkChip](/ui/storybook/?path=/docs/ui-primitives-linkchip--docs) [LinkCard](/ui/storybook/?path=/docs/ui-primitives-linkcard--docs) [PreviewCard](/ui/storybook/?path=/docs/ui-primitives-previewcard--docs) [FilterMenu](/ui/storybook/?path=/docs/ui-filtermenu--docs) [Table](/ui/storybook/?path=/docs/ui-primitives-table--docs)

**Build navigation from these and leave their look alone. A hand-made row or tab draws its own current state, and an app's places then read differently from screen to screen.**

```tsx
import {
  NavList,
  NavListCount,
  NavListFrame,
  NavListHeading,
  NavListItem,
  NavListLink,
} from "@orz/ui/components/nav-list";
import { Pane } from "@orz/ui/components/pane";
import { TabNav, TabNavLink } from "@orz/ui/components/tab-nav";
import { isPlainClick } from "@orz/ui/lib/link";
import {
  ArchiveIcon,
  FileTextIcon,
  InboxIcon,
  SendIcon,
  TagIcon,
} from "lucide-react";
import { useState } from "react";

const SECTIONS = ["Mail", "Calendar", "Contacts"];

const FOLDERS = [
  { title: "Inbox", Icon: InboxIcon, count: 8 },
  { title: "Sent", Icon: SendIcon, count: 0 },
  { title: "Drafts", Icon: FileTextIcon, count: 1 },
  { title: "Archive", Icon: ArchiveIcon, count: 0 },
];

const LABELS = ["review", "release", "support"];

export function AppFrame() {
  const [section, setSection] = useState("Mail");
  const [place, setPlace] = useState("Inbox");
  return (
    <Pane purpose="app" className="flex h-80 flex-col">
      <Pane
        purpose="banner"
        edge="bottom"
        asChild
        className="flex h-11 shrink-0 items-stretch gap-4 px-3"
      >
        <header>
          <span className="flex items-center font-semibold text-ui">
            Office
          </span>
          <TabNav aria-label="Sections">
            {SECTIONS.map((name) => (
              <TabNavLink
                key={name}
                href={`#${name.toLowerCase()}`}
                current={name === section}
                onClick={(event) => {
                  if (!isPlainClick(event)) return;
                  event.preventDefault();
                  setSection(name);
                }}
              >
                {name}
              </TabNavLink>
            ))}
          </TabNav>
        </header>
      </Pane>
      <div className="flex min-h-0 flex-1">
        <Pane
          purpose="sidebar"
          edge="end"
          className="flex w-48 shrink-0 flex-col"
        >
          <NavListFrame className="min-h-0 flex-1">
            <nav aria-label="Folders" className="h-full overflow-y-auto py-2">
              <NavList>
                {FOLDERS.map(({ title, Icon, count }) => (
                  <NavListItem key={title}>
                    <NavListLink
                      href={`#${title.toLowerCase()}`}
                      current={title === place}
                      onClick={(event) => {
                        if (!isPlainClick(event)) return;
                        event.preventDefault();
                        setPlace(title);
                      }}
                    >
                      <Icon />
                      {title}
                      {count > 0 && <NavListCount>{count}</NavListCount>}
                    </NavListLink>
                  </NavListItem>
                ))}
                <NavListItem>
                  <NavListHeading asChild>
                    <h3>Labels</h3>
                  </NavListHeading>
                  <NavList>
                    {LABELS.map((label) => (
                      <NavListItem key={label}>
                        <NavListLink
                          href={`#${label}`}
                          current={label === place}
                          onClick={(event) => {
                            if (!isPlainClick(event)) return;
                            event.preventDefault();
                            setPlace(label);
                          }}
                        >
                          <TagIcon />
                          {label}
                        </NavListLink>
                      </NavListItem>
                    ))}
                  </NavList>
                </NavListItem>
              </NavList>
            </nav>
          </NavListFrame>
        </Pane>
        <Pane purpose="document" className="min-w-0 flex-1">
          <p className="p-4 text-muted-foreground text-ui">
            {section} · {place}
          </p>
        </Pane>
      </div>
    </Pane>
  );
}
```

The header's `TabNav` holds the app's sections; the sidebar's `NavList` holds the places inside the one that is open, under a heading for each group. Pick a section or a folder: the current one is marked the same way in both, by weight, with an underline on the header's rule or a tick on the row's leading edge.

## Which one

| You need to                                                                                                               | Use                                                                                                                                                                                                                                                           |
| ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Go between an app's few top-level sections, from its header                                                               | `TabNav`, with a `TabNavLink` for each                                                                                                                                                                                                                        |
| Go between the few pages of one item, each with its own address: a pull request's conversation, commits, checks and files | `TabNav`, on a rule under the item's own header                                                                                                                                                                                                               |
| Go between many places: folders, settings sections, files, a document's parts                                             | `NavList`, a `NavListLink` for each, `NavListHeading` over each group                                                                                                                                                                                         |
| Let the reader close a group of places they seldom need                                                                   | `NavListGroup`, headed by a `NavListHeading` holding a `NavListGroupToggle`, or by a `NavListGroupRow` when the group has a page of its own                                                                                                                   |
| Go between places in a hierarchy the reader opens and closes: folders, machines, a file's parts                           | `Tree`, a `TreeItem` for each place                                                                                                                                                                                                                           |
| Show where a page sits in a hierarchy, and go up or across from it                                                        | `Breadcrumb`: a `BreadcrumbItem` for each level, its `BreadcrumbLink` then a `BreadcrumbMenu` of the pages under it, the last one `BreadcrumbPage`                                                                                                            |
| Go between a repository's files and folders, by path                                                                      | `FileTree`, a `FileTreeItem` for each                                                                                                                                                                                                                         |
| Go to a section of the page in view, from a column beside it                                                              | `NavList variant="rail"`                                                                                                                                                                                                                                      |
| Go to one of more places than a header has room for, by name: the project, repository or workspace the app is in          | `FilterMenu` behind a button naming the current one, each row a link through `rowLink`                                                                                                                                                                        |
| Point at one thing (a card, a file, a page) from inside a sentence, with its icon                                         | `LinkChip`; `wrap` where it sits in running text and its label may be long                                                                                                                                                                                    |
| Send the reader to another place, saying what is there                                                                    | `LinkCard`, with a `LinkCardTitle` and a `LinkCardDescription`: a card on the ground, `variant="tile"` inside a card, a pane or a sheet, `variant="row"` for a list of pages ([Surfaces](/ui/guidelines/foundations/surfaces/index.md#links-to-other-places)) |
| Send the reader to another place whose look is what there is to say: a wall of demos                                      | `PreviewCard` on the ground: a `PreviewCardPicture` of the place, its `PreviewCardTitle` holding the `PreviewCardLink`, a `PreviewCardLabel` and a `PreviewCardDescription` ([Surfaces](/ui/guidelines/foundations/surfaces/index.md#links-to-other-places))  |
| Show one of a few views of one block among others in a surface's flow: a sample's states, a group of code files           | `Tabs variant="framed"`, the strip on the frame's lid, a `FrameBar`, with any other controls beside the tabs                                                                                                                                                  |
| Switch everything a pane shows below its header: a release's overview, log and diff                                       | `Tabs variant="pane"`: the strip a line across the pane's row, the current panel filling the rest and scrolling on its own                                                                                                                                    |
| Switch everything a module on the ground shows: a workspace's members and invitations                                     | A `Card` holding `Tabs variant="pane"`: the strip the card's head, the panel the rest of the card                                                                                                                                                             |
| The same, where the strip shares a bar with other parts over a region with a surface of its own                           | `Tabs`, its strip a line laid flush on the bar's bottom rule                                                                                                                                                                                                  |

A `LinkChip` with `wrap` is text in the line: its label breaks between words with the sentence around it, and a sentence copied across it pastes as the words on screen, with no line break added. A part of the label the reader would not want in a copy, such as the title beside a card's number, takes `select-none`, the space before it included; a part that must not break, such as the number, takes `whitespace-nowrap`.

A `NavList` that is a pane of the app's frame, as a mail client's folders beside its messages are, sits in a `NavListFrame` around its `nav`, its headings and its scroller, which a style may draw as a well. One in a `Sheet` does not: the sheet is its frame.

`Tabs` switch panels and keep the page's URL; `TabNav` and `NavList` go somewhere, and each place is a link to its URL, so a middle click, a modified click and the context menu all work as they do on any link ([A place is a link](/ui/guidelines/principles/index.md#a-place-is-a-link)). Pass a router's link with `asChild`; an app that moves in place by hand keeps the `href` and returns early from its click handler unless `isPlainClick(event)` from `@orz/ui/lib/link`. The same holds off these components: a row that opens an item, a **Back** to the list, a **Clear search** that returns to a folder, each is a link, drawn by `Button asChild` or `ListItem asChild` around the `a`, or, for the name in a table's row, by `TableRowLink`.

```tsx
import { CI_RUN } from "@orz/fixtures/ci-run.ts";
import {
  Tabs,
  TabsContent,
  TabsList,
  TabsTrigger,
} from "@orz/ui/components/tabs";

export function LineTabs() {
  return (
    <Tabs defaultValue="summary">
      <TabsList variant="line">
        <TabsTrigger value="summary">Summary</TabsTrigger>
        <TabsTrigger value="jobs">Jobs</TabsTrigger>
      </TabsList>
      <TabsContent value="summary">
        <p className="text-ui">{CI_RUN.jobs.length} jobs ran on this push.</p>
      </TabsContent>
      <TabsContent value="jobs">
        <ul className="grid gap-1 text-ui">
          {CI_RUN.jobs.map((job) => (
            <li key={job.id}>
              {job.name}: {job.status}
            </li>
          ))}
        </ul>
      </TabsContent>
    </Tabs>
  );
}
```

On a frame's lid the current tab is cut out of the bar into the panel below it. Anywhere else a strip of tabs is a line, the current one underlined on its rule: there is no panel under it to cut the tab into, and a cut-out would hang over whatever lies there, as it would over a demo's own sidebar under the bar above. `TabsList variant="line"` asks for the line on a frame's lid too. In a pane's set the line is the pane's whole row, its rule from side to side, and the first tab's words stand a card's padding in from the pane's edge, in line with a header padded as a card is.

## When the sections do not fit

```tsx
import { Button } from "@orz/ui/components/button";
import { Frame } from "@orz/ui/components/frame";
import { Input } from "@orz/ui/components/input";
import { Pane } from "@orz/ui/components/pane";
import { TabNav, TabNavLink } from "@orz/ui/components/tab-nav";
import { isPlainClick } from "@orz/ui/lib/link";
import { PlusIcon } from "lucide-react";
import { useState } from "react";

const SECTIONS = ["List", "Board", "Insights", "Settings"];

// The frame's corner drags it narrower. The search gives up its room first,
// down to its least; then the sections fold into the ⋯, the current one
// last; only then does the project's name truncate. The search takes no
// room of its own to start from (`basis-0`), so it grows only into what the
// sections leave.
export function SectionsHeader() {
  const [section, setSection] = useState("Board");
  return (
    <Frame inset className="w-3xl min-w-48 max-w-full resize-x overflow-hidden">
      <Pane
        purpose="banner"
        edge="bottom"
        asChild
        className="flex items-center gap-3 px-3"
      >
        <header>
          <span className="min-w-0 truncate font-semibold text-ui">
            Website relaunch
          </span>
          <TabNav aria-label="Project">
            {SECTIONS.map((name) => (
              <TabNavLink
                key={name}
                href={`#${name.toLowerCase()}`}
                current={name === section}
                onClick={(event) => {
                  if (!isPlainClick(event)) return;
                  event.preventDefault();
                  setSection(name);
                }}
              >
                {name}
              </TabNavLink>
            ))}
          </TabNav>
          <Input
            type="search"
            aria-label="Search issues"
            placeholder="Search…"
            className="my-2 max-w-64 min-w-32 flex-1 basis-0"
          />
          <Button>
            <PlusIcon />
            New issue
          </Button>
        </header>
      </Pane>
    </Frame>
  );
}
```

A `TabNav` that runs out of room moves its links into a ⋯ at its end, from the last one back, the current one last; they come back in the same order as the room does. How many fit follows the widths the style and the pointer draw them at, so never hide a section by a breakpoint, which is measured off one name and is wrong for the next. Give the sections in the order of how much they matter: the last ones wait in the ⋯ first.

The current section stays on the row with its mark as long as it fits there at all: when it and the ⋯ no longer fit, its name is cut short, down to two letters and an ellipsis. Only a row too narrow for even that puts it in the ⋯, which then wears the mark and names the section in its own name, and the section is marked in the menu. Each row of the menu is the same link, so a router's link passed with `asChild` and a modified click work there as on the row.

In a header it shares a row with other parts, and takes the room its links need before anything that grows beside it, and gives it up, down to the current section and the ⋯, before anything that shrinks. Drag the corner above: the search gives up its room first, then the sections fold, and only then does the project's name truncate. For that order, give a part that grows beside it, a search, `flex-1 basis-0` and its bounds (`min-w-32 max-w-64`), and let a name truncate with `min-w-0 truncate`. Do not order them with shrink weights (`shrink-[…]`): the `TabNav` still takes a share of every shortfall and folds a section while the search has room to spare.

A strip of `Tabs` folds the same way, framed or a line: the tabs that do not fit wait in a ⋯ at the strip's end, the current one last and cut short before it goes, and a tab picked there is the current one, back on the strip. The ⋯ stands beside the tab list rather than in it, so the arrow keys go between the tabs on the strip and Tab comes to the ⋯ after them. On a frame's lid, beside commands, the tabs give up their room down to the current one and the ⋯ before the bar moves a command into its own ⋯. Never scroll a strip of tabs sideways instead: a mouse has no way to see or reach what scrolled away.

## Switching between many places

```tsx
import { Button } from "@orz/ui/components/button";
import {
  FilterMenu,
  MatchedText,
  matchText,
} from "@orz/ui/components/filter-menu";
import { Frame } from "@orz/ui/components/frame";
import { Pane } from "@orz/ui/components/pane";
import { TabNav, TabNavLink } from "@orz/ui/components/tab-nav";
import { isPlainClick } from "@orz/ui/lib/link";
import { ChevronsUpDownIcon } from "lucide-react";
import { type MouseEvent, useState } from "react";

const PROJECTS = [
  { id: "website-relaunch", label: "Website relaunch" },
  { id: "mobile-app", label: "Mobile app" },
  { id: "billing", label: "Billing" },
  { id: "design-system", label: "Design system" },
  { id: "data-platform", label: "Data platform" },
  { id: "help-centre", label: "Help centre" },
  { id: "onboarding", label: "Onboarding" },
  { id: "security-review", label: "Security review" },
] as const;

type Project = (typeof PROJECTS)[number];

const SECTIONS = ["List", "Board", "Insights"];

// Each project row links to the same section of that project. A plain click
// goes in place, as an app's router would; any other click is the browser's,
// and opens the project in a new tab.
export function ProjectSwitcher() {
  const [project, setProject] = useState<Project>(PROJECTS[0]);
  const [section, setSection] = useState("Board");
  const [query, setQuery] = useState("");
  const href = (id: string, name: string) => `#${id}/${name.toLowerCase()}`;
  const inPlace = (go: () => void) => (event: MouseEvent) => {
    if (!isPlainClick(event)) return;
    event.preventDefault();
    go();
  };
  return (
    <Frame inset>
      <Pane
        purpose="banner"
        edge="bottom"
        asChild
        className="flex items-center gap-3 px-3"
      >
        <header>
          <FilterMenu
            query={query}
            onQueryChange={setQuery}
            sections={[
              {
                id: "projects",
                rows: PROJECTS.filter((row) => matchText(row.label, query)),
              },
            ]}
            selectedId={project.id}
            rowLink={(row) => (
              // biome-ignore lint/a11y/useAnchorContent: the row's content goes inside
              <a
                href={href(row.id, section)}
                onClick={inPlace(() => setProject(row))}
              />
            )}
            renderRow={(row, state) => (
              <MatchedText text={row.label} query={state.query} />
            )}
            placeholder="Filter projects…"
            inputLabel="Filter projects"
            listLabel="Projects"
            className="w-64"
          >
            <Button variant="ghost" size="sm" className="min-w-0">
              <span className="truncate">{project.label}</span>
              <ChevronsUpDownIcon className="text-muted-foreground" />
            </Button>
          </FilterMenu>
          <TabNav aria-label="Project">
            {SECTIONS.map((name) => (
              <TabNavLink
                key={name}
                href={href(project.id, name)}
                current={name === section}
                onClick={inPlace(() => setSection(name))}
              >
                {name}
              </TabNavLink>
            ))}
          </TabNav>
        </header>
      </Pane>
    </Frame>
  );
}
```

A switcher goes to one of more places than a header has room for, the reader finding it by name: the project the app is in, here, or a repository, a workspace. It is a `FilterMenu` behind a button that names the current one, and each of its rows is a link: `rowLink` returns its `href`, or a router's link, here to the same section of the other project, since the header's sections stay where they are.

A plain click or Enter goes there and closes the menu. A middle or modified click opens the project in a new tab and leaves the menu open for the next one, and a row drags onto the bookmarks bar as any link does. A router's link, returned with no children, keeps its own handling, as one passed with `asChild` does. `onSelect` only hears that a row was picked: do not navigate there as well.

## A path back up

```tsx
import {
  Breadcrumb,
  BreadcrumbItem,
  BreadcrumbLink,
  BreadcrumbMenu,
  BreadcrumbMenuLink,
  BreadcrumbPage,
} from "@orz/ui/components/breadcrumb";
import { Frame } from "@orz/ui/components/frame";
import { Pane } from "@orz/ui/components/pane";
import { isPlainClick } from "@orz/ui/lib/link";
import { type MouseEvent, useState } from "react";

interface Page {
  name: string;
  children?: Page[];
}

const HANDBOOK: Page = {
  name: "Handbook",
  children: [
    {
      name: "Engineering",
      children: [
        {
          name: "Onboarding",
          children: [
            { name: "Laptop setup" },
            { name: "First week" },
            { name: "Access requests" },
          ],
        },
        {
          name: "On call",
          children: [{ name: "Rotation" }, { name: "Escalation" }],
        },
      ],
    },
    {
      name: "Design",
      children: [
        {
          name: "Research",
          children: [{ name: "Interviews" }, { name: "Surveys" }],
        },
      ],
    },
  ],
};

/** The pages from the handbook down to the one named last in `path`. */
function pagesOn(path: readonly string[]): Page[] {
  const pages = [HANDBOOK];
  for (const name of path.slice(1)) {
    const next = pages.at(-1)?.children?.find((page) => page.name === name);
    if (!next) break;
    pages.push(next);
  }
  return pages;
}

const hrefOf = (path: readonly string[]) =>
  `#${path.map((name) => name.toLowerCase().replace(/ /g, "-")).join("/")}`;

// The frame's corner drags it narrower: the levels after the first go into
// the … from the second on, then the first, and only then is the page's name
// cut short. Every level and every row is a link; a plain click goes in
// place, as an app's router would.
export function BreadcrumbPath() {
  const [path, setPath] = useState([
    "Handbook",
    "Engineering",
    "Onboarding",
    "Laptop setup",
  ]);
  const pages = pagesOn(path);
  const go = (to: string[]) => (event: MouseEvent) => {
    if (!isPlainClick(event)) return;
    event.preventDefault();
    setPath(to);
  };
  return (
    <Frame inset className="w-3xl min-w-32 max-w-full resize-x overflow-hidden">
      <Pane
        purpose="banner"
        edge="bottom"
        asChild
        className="flex items-center px-2 py-1.5"
      >
        <header>
          <Breadcrumb aria-label="Handbook">
            {pages.map((page, depth) => {
              const to = path.slice(0, depth + 1);
              const last = depth === pages.length - 1;
              return (
                <BreadcrumbItem key={to.join("/")}>
                  {last ? (
                    <BreadcrumbPage>{page.name}</BreadcrumbPage>
                  ) : (
                    <BreadcrumbLink href={hrefOf(to)} onClick={go(to)}>
                      {page.name}
                    </BreadcrumbLink>
                  )}
                  {!last && (
                    <BreadcrumbMenu label={`Pages in ${page.name}`}>
                      {page.children?.map((child) => {
                        const next = [...to, child.name];
                        return (
                          <BreadcrumbMenuLink
                            key={child.name}
                            href={hrefOf(next)}
                            current={child.name === path[depth + 1]}
                            onClick={go(next)}
                          >
                            {child.name}
                          </BreadcrumbMenuLink>
                        );
                      })}
                    </BreadcrumbMenu>
                  )}
                </BreadcrumbItem>
              );
            })}
          </Breadcrumb>
        </header>
      </Pane>
      <Pane purpose="document" className="px-4 py-6">
        <p className="font-semibold text-heading-3">{pages.at(-1)?.name}</p>
      </Pane>
    </Frame>
  );
}
```

A `Breadcrumb` shows the way from the top of a hierarchy down to the page on screen, and goes up or across it in one step. Each level's separator is its menu: `Pages in <level>` lists the pages under that level, which are the next level and its siblings, the one the path goes through checked, and a folder among them opens into a submenu of its own pages. Every level is a link to its page and every row of a menu is a link, so a middle click, a modified click and the context menu work on them as on any link; the page on screen is words, not a link, and a level with no page of its own (a folder, a heading) is words whose separator still opens. Under the pointer, on the keyboard's focus and while its menu is open the › turns to ⌄, so the reader sees it opens.

Put it in a bar, as above, or over a page's title as this site does over each guideline, with `flush`, so the first level's words line up with the title's. In a `Toolbar` it takes the bar's size and its links and separators join the bar's arrow keys.

When the levels do not fit, they wait in a … from the second level on, the first and the last staying longest: the first is the hierarchy's top, the project or the section, and the last is where the reader is. The last level folded keeps its separator after the …, its menu still there. Only when the …, that separator and the page are all that is left is the page's name cut short. How many fit follows the widths the style and the pointer draw them at, so never hide a level by a breakpoint.

## Groups that open and close

```tsx
import {
  NavList,
  NavListFrame,
  NavListGroup,
  NavListGroupContent,
  NavListGroupRow,
  NavListGroupToggle,
  NavListHeading,
  NavListItem,
  NavListLink,
} from "@orz/ui/components/nav-list";
import { isPlainClick } from "@orz/ui/lib/link";
import { FolderArchiveIcon, FolderIcon } from "lucide-react";
import { type MouseEvent, useState } from "react";

const PROJECTS = [
  { id: "website", name: "Website", pages: ["Issues", "Board", "Releases"] },
  { id: "mobile-app", name: "Mobile app", pages: ["Issues", "Board"] },
];

const ARCHIVED = [
  { id: "old-site", name: "Old site" },
  { id: "pilot", name: "Pilot" },
];

export function CollapsibleGroups() {
  const [current, setCurrent] = useState("website/board");
  const go = (place: string) => (event: MouseEvent) => {
    if (!isPlainClick(event)) return;
    event.preventDefault();
    setCurrent(place);
  };
  return (
    <NavListFrame className="max-w-64">
      <nav aria-label="Projects" className="py-2">
        <NavList>
          {PROJECTS.map((project) => (
            <NavListItem key={project.id}>
              <NavListGroup>
                <NavListGroupRow>
                  <NavListLink
                    href={`#${project.id}`}
                    current={current === project.id}
                    onClick={go(project.id)}
                  >
                    <FolderIcon />
                    {project.name}
                  </NavListLink>
                  <NavListGroupToggle />
                </NavListGroupRow>
                <NavListGroupContent>
                  <NavList>
                    {project.pages.map((page) => {
                      const place = `${project.id}/${page.toLowerCase()}`;
                      return (
                        <NavListItem key={page}>
                          <NavListLink
                            href={`#${place}`}
                            depth={1}
                            current={current === place}
                            onClick={go(place)}
                          >
                            {page}
                          </NavListLink>
                        </NavListItem>
                      );
                    })}
                  </NavList>
                </NavListGroupContent>
              </NavListGroup>
            </NavListItem>
          ))}
          <NavListItem>
            <NavListGroup defaultOpen={false}>
              <NavListHeading asChild>
                <h3>
                  <NavListGroupToggle>Archived</NavListGroupToggle>
                </h3>
              </NavListHeading>
              <NavListGroupContent>
                <NavList>
                  {ARCHIVED.map((project) => (
                    <NavListItem key={project.id}>
                      <NavListLink
                        href={`#${project.id}`}
                        current={current === project.id}
                        onClick={go(project.id)}
                      >
                        <FolderArchiveIcon />
                        {project.name}
                      </NavListLink>
                    </NavListItem>
                  ))}
                </NavList>
              </NavListGroupContent>
            </NavListGroup>
          </NavListItem>
        </NavList>
      </nav>
    </NavListFrame>
  );
}
```

When a column holds many groups and the reader works in one or two of them, let the groups close in a `NavListGroup`. A few groups of a few places each stay open: closing them only costs the reader clicks. A group with no page of its own makes its `NavListHeading` the toggle. A group that is a place heads itself with a `NavListGroupRow`: its link goes to the place, and opens the group too if it was closed, never closing it; the toggle at the row's end does the opening and closing.

A group the reader has not touched is open exactly while it holds the current place, from the first frame. Once the reader closes it over the current place, its head is drawn as current, so the reader still sees where they are. Groups hold no groups: deeper places, opened and closed as the reader works, are a [`Tree`](#trees).

## Trees

```tsx
import { NavListFrame } from "@orz/ui/components/nav-list";
import { Tree, TreeCount, TreeItem, TreeLabel } from "@orz/ui/components/tree";
import { isPlainClick } from "@orz/ui/lib/link";
import { FolderIcon, FolderOpenIcon, InboxIcon, SendIcon } from "lucide-react";
import { useState } from "react";

interface Folder {
  id: string;
  name: string;
  unread?: number;
  children?: Folder[];
}

const FOLDERS: Folder[] = [
  {
    id: "inbox",
    name: "Inbox",
    unread: 8,
    children: [
      {
        id: "projects",
        name: "Projects",
        unread: 3,
        children: [
          { id: "website", name: "Website", unread: 2 },
          { id: "mobile-app", name: "Mobile app", unread: 1 },
          { id: "archive-2025", name: "2025" },
        ],
      },
      { id: "receipts", name: "Receipts" },
      { id: "newsletters", name: "Newsletters", unread: 5 },
    ],
  },
  { id: "sent", name: "Sent" },
  {
    id: "archive",
    name: "Archive",
    children: [
      { id: "archive-2024", name: "2024" },
      { id: "archive-2023", name: "2023" },
    ],
  },
];

export function FolderTree() {
  const [current, setCurrent] = useState("website");
  return (
    <NavListFrame className="max-w-64">
      <nav aria-label="Mail" className="py-2">
        <Tree aria-label="Folders" items={FOLDERS} current={current}>
          {(folder, row) => {
            const Icon =
              folder.id === "inbox"
                ? InboxIcon
                : folder.id === "sent"
                  ? SendIcon
                  : row.expanded
                    ? FolderOpenIcon
                    : FolderIcon;
            return (
              <TreeItem
                href={`#${folder.id}`}
                onClick={(event) => {
                  if (!isPlainClick(event)) return;
                  event.preventDefault();
                  setCurrent(folder.id);
                }}
              >
                <Icon />
                <TreeLabel>{folder.name}</TreeLabel>
                {folder.unread && <TreeCount>{folder.unread}</TreeCount>}
              </TreeItem>
            );
          }}
        </Tree>
      </nav>
    </NavListFrame>
  );
}
```

Places nested a level or two and always shown open are a `NavList`, each level a `depth` deeper; one level the reader may close is a [group](#groups-that-open-and-close). When the reader opens and closes the branches, or the nesting runs as deep as the data does, they are a `Tree`. A click on a place goes there, and opens it as well if it was closed; only the toggle beside it, or ←, closes it, so going to a folder never hides what is in it.

Mark the place on screen with `current`: the tree opens the way to it, and the keyboard starts there. An app that holds the open branches itself starts them from `ancestorsOf`, so the first frame already shows the place. When a filter leaves no row, the tree draws nothing; show an `EmptyState` in its place.

A long tree mounts only the rows near the screen, so the browser's find in page cannot reach the rest: give it a filter box. Give a deep one, a file tree above all, a scroller of its own and `stickyBranches`, so the folders the reader has scrolled into stay pinned at its top and they always see where they are. The tree scrolls `current` into sight as it changes; an app that keeps the scroll position itself turns that off with `revealCurrent={false}`, and scrolls with the `scrollToItem` of the tree's `handle` when it means to.

### Sections

When a tree's places come from a few sources the reader tells apart, such as the folders of a workspace, or a demo's own files and the fixtures it reads, head each source with a section: a root with `section` set draws that text over its children, which stand as roots under it. Keep them in one tree rather than a tree under each `NavListHeading`: the arrows, typing a name and a selection run on from one section into the next, where separate trees would each be a stop of their own. A heading is no place: nothing goes to it, it never closes, and it goes when a filter leaves its section empty. Under `stickyBranches` it pins above the section's folders. A `FileTree` takes `sections` as folders, each headed by its path, as every demo's Code view and the [Config editor](/ui/demos/config-editor/index.md) list their files.

### Renaming, moving and a row's menu

When the places in a tree are the reader's own (their folders, their notes, their files), let them rename and move them where they stand: `onRename` renames a row in place on F2, and `onMove` takes a dragged row, or one cut and pasted with Ctrl+X and Ctrl+V, which is how the keyboard and a touch screen move one. The tree changes nothing itself; the app changes its data and passes it back. A tree the reader orders by hand accepts a row before, into or after another; a tree that sorts itself accepts one only into a branch, as a `FileTree` does.

A right click stays the browser's, with the link's own menu; put the app's actions for a row in `menu`, which draws a ⋯ button at the row's end and opens on Shift+F10 too. Do not ask before a rename, a move or a delete: do it, then say what was done in a toast with **Undo**, as the [Repository demo](/ui/demos/repository/index.md) does. A `FileTree` hands over each change as the path before and after; `movePath` applies it to the app's paths and statuses, and to its sections, which follow their folders when a folder above them moves.

### Selecting several

Give a tree `selectable` when the reader will do one thing to several of their own places at once: move a handful of files into a folder, delete a batch of drafts. Selecting is not going: a click on a row's name still goes to its place, and a modified or middle click is still the link's.

- With a pointer, a checkbox stands in for a row's icon while the pointer is on it, and a click there selects; Shift and a click on another icon selects the rows between, and a press on an icon dragged down or up the rows selects each row it passes, or deselects them when the first row was selected. A drag from a row's name still moves it. From the keyboard, Space toggles the focused row, Shift with the arrows extends from it, and Ctrl+A takes every row.
- On a touch screen, the row's menu starts it: put `select` in `menu` as **Select**, and after the first row each tap toggles a row instead of going. Put `clearSelection` there too, so the way back is never only a toolbar.
- Dragging a selected row, cutting it or opening its menu acts on the whole selection, and `onMove` hears the group at once. A menu acting on several says how many ("Delete 3 items").
- Follow `onSelectedChange` with a [`SelectionBar`](/ui/guidelines/patterns/actions-and-buttons/index.md#acting-on-a-selection) over the tree: how many are selected, the actions that take them all, and the way out. `onShownChange` hands over the rows on screen, which are what its select-all takes. A batch action, like any other, is done at once and said in a toast with **Undo**.
- Only the rows on screen are selected: closing a folder, or filtering a row away, takes its rows out of the selection, so an action never reaches a row the reader cannot see.

### Files

```tsx
import { EmptyState } from "@orz/ui/components/empty-state";
import { FileTree, FileTreeItem } from "@orz/ui/components/file-tree";
import { Input } from "@orz/ui/components/input";
import { NavListFrame } from "@orz/ui/components/nav-list";
import type { FileStatus } from "@orz/ui/lib/file-tree";
import { isPlainClick } from "@orz/ui/lib/link";
import { SearchIcon } from "lucide-react";
import { useState } from "react";

const PATHS = [
  ".github/workflows/ci.yml",
  ".env.local",
  "README.md",
  "package.json",
  "dist/bundle.zip",
  "docs/guide.md",
  "docs/old-guide.md",
  "src/fetch-task.ts",
  "src/retry.ts",
  "src/index.ts",
];

const STATUS: Record<string, FileStatus> = {
  ".env.local": "untracked",
  "dist/": "ignored",
  "docs/old-guide.md": "deleted",
  "src/fetch-task.ts": "modified",
  "src/retry.ts": "added",
};

export function RepositoryFiles() {
  const [current, setCurrent] = useState("src/retry.ts");
  const [query, setQuery] = useState("");
  const needle = query.trim().toLowerCase();
  const matches = PATHS.filter((path) =>
    path.toLowerCase().includes(needle),
  ).length;
  return (
    <NavListFrame className="max-w-72">
      <nav aria-label="Repository" className="flex flex-col gap-2 py-2">
        <div className="px-2">
          <Input
            aria-label="Filter files"
            placeholder="Filter files"
            value={query}
            onChange={(event) => setQuery(event.target.value)}
          />
        </div>
        {/* Always there, so the first count is read out as it appears. */}
        <p
          aria-live="polite"
          className="px-3 text-ui-sm text-muted-foreground empty:hidden"
        >
          {needle === ""
            ? null
            : matches === 1
              ? "1 file matches"
              : `${matches} files match`}
        </p>
        {needle !== "" && matches === 0 ? (
          <EmptyState icon={SearchIcon} title="No files match" />
        ) : (
          <FileTree
            aria-label="Files"
            paths={PATHS}
            status={STATUS}
            current={current}
            query={query}
          >
            {(file) => (
              <FileTreeItem
                href={`#${file.path}`}
                onClick={(event) => {
                  if (!isPlainClick(event)) return;
                  event.preventDefault();
                  setCurrent(file.path);
                }}
              />
            )}
          </FileTree>
        )}
      </nav>
    </NavListFrame>
  );
}
```

When the places are files known by their paths, as a repository's or a folder's are, use a `FileTree`: it takes the paths as they come, puts folders first, merges a chain of folders that hold one folder each into one row, and draws each file's type as its icon. Use a plain `Tree` when the data is not paths, or when its folders load as the reader opens them.

Give it each file's status, and it marks the row: a letter at the end in the status's colour (**A**dded, **M**odified, **D**eleted, **R**enamed, **U**ntracked), the name in that colour too and struck through when deleted, a dot on a folder holding a change, and an ignored file or folder faded, with everything under an ignored folder. The current file's name keeps the tree's own colour, the place outranking its status; the letter still says it.

A filter by text can leave only the matches (`filterMode="hide"`, the default), for finding one file. It can keep every row and open the folders on the way to each match (`"expand"`), to see the matches among their neighbours, or open those folders alone and close the rest (`"collapse"`), to see which parts of the tree the matches fall in. Under either of the last two the reader opens and closes folders for the search alone, and clearing it brings back the folders as they were. Say how many files match, and say it when none do.

## Marking where the reader is

- Mark exactly one place with `current`. It sets `aria-current` and draws the state; a row or a tab never adds a fill or a bar of its own.
- `current` is `"page"` by default. A part of a document in view is `current="location"`.
- A section in `TabNav` stays current on every page inside it, not only on its own first page.
- Nest places that stay open with `depth`, one step per level, rather than wrapping a list in an indented box; nest places the reader opens and closes in a `NavListGroup`, or a `Tree` when they run deeper than one level.

## On each platform

### Desktop & pointer

Rows run at the dense row height, with the count, size or offset at the row's end in tabular figures (`NavListCount`).

### Touch & mobile

Under a coarse pointer every row and tab makes room for a thumb by itself. A `Breadcrumb`'s separators stay ›, as nothing on a touch screen points at them; a tap opens one, its menu a sheet from the bottom on a phone. On a phone, a few sections with no list of places each keep their `TabNav`, on a row of its own under the header, and what does not fit waits in its ⋯. Sections that each hold a list of places go in a `Sheet` opened from the header, as a `NavList` with each section a `NavListGroup` of its places, open on the section the reader is in, as this site does.

## In the demos

- [Releases](/ui/demos/releases/index.md): The sections, the sidebar's places and each release's title are links to this page's address for them, so a middle click opens any in a new tab and Back steps through them.
- [Admin](/ui/demos/admin/index.md): The sections in the top bar and the workspaces in its menu are links to this page's address for them, so a middle click opens any in a new tab and Back steps through them.
- [Mail](/ui/demos/mail/index.md): The folders and labels are a NavList under a heading for each group, each place a link, so it opens in a new tab too; the folder on screen is the one marked.
- [Repository](/ui/demos/repository/index.md): The files are a FileTree, each file and folder a link to its path, so a middle click opens it in a new tab and a reload stays on it. The path above the file links each folder on the way. Type retry in the filter, then switch the filter mode from the menu beside it: Hide other files keeps the matches, Open folders with matches keeps every row, and Close other folders opens only the matches' folders.
- [Config editor](/ui/demos/config-editor/index.md): The files are a FileTree beside the open one, under a section headed by their folder. The Code view beside the demo lays out its own files the same way, a section for each folder they come from.
