Navigation
TabNav, Breadcrumb, NavList, Tree and Tabs: where the reader is, and how they get somewhere else, drawn the same way in every app.
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.
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) |
| 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) |
| 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). 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.
3 jobs ran on this push.
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#
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#
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#
Laptop setup
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#
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#
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. 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 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 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
selectinmenuas Select, and after the first row each tap toggles a row instead of going. PutclearSelectionthere 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
onMovehears the group at once. A menu acting on several says how many ("Delete 3 items"). - Follow
onSelectedChangewith aSelectionBarover the tree: how many are selected, the actions that take them all, and the way out.onShownChangehands 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#
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 (Added, Modified, Deleted, Renamed, Untracked), 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 setsaria-currentand draws the state; a row or a tab never adds a fill or a bar of its own. currentis"page"by default. A part of a document in view iscurrent="location".- A section in
TabNavstays 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 aNavListGroup, or aTreewhen 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
- ReleasesThe 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.
- AdminThe 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.
- MailThe 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.
- RepositoryThe 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 editorThe 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.