Raft Design System

Components · Navigation

TabBar

A pane's first row — its tabs, then only + and Maximize (Restore while maximized), with All tabs while the tabs don't fit; it fits the tabs by one width rule.

ExperimentalAlso called Tab strip, Tab row, Pane tabs, All tabs, Tab overflow
import { TabBar } from "@botiverse/raft-ui/wip";

TabBar is a pane's first row: its Tabs, then at its end only + and Maximize (pressed, as Restore, while maximized), with All tabs before them while the tabs don't fit. It fits its tabs by one width rule, and has no ⋯: what is done to a tab or its pane is in the tab's menu (Tabs and panes).

tab-bar/compositions/preview

When to use

SituationUse
The tabs of a pane beside a conversationTabBar
The sections of one pageTabs
A row of buttons for the front objectPaneToolRow

Anatomy

  • The tab area: Tabs › TabsList, named by label, holding the children (the pane's tabs, pinned ones first; the workspace tabs pin none for now, Tabs and panes), then a divider and the merged tabs in a narrow window, or a divider and the squeezed tabs while the pane is maximized (Merged and squeezed tabs). The tab whose value is the bar's value is in front; the bar's density reaches every tab.
  • All tabs: a ghost Button opening a DropdownMenu of every tab in children, then a divider and every tab in merged, then a divider and every tab in squeezed, the front one checked. Only while the tabs don't fit.
  • The + button (onNewTab) and Maximize (onToggleMaximize): PanelActions with tooltips. Maximize is a PanelToggleAction: pressed while maximized, with minimize-2 and the name Restore, as a panel's Expand and its Restore are.
  • The insertion line, while a tab is dropped into the bar: among its own tabs (insertAt) or its merged ones (mergedInsertAt).

Width

One rule, the same for every tab, in front or not, its own or merged, so choosing or hovering a tab never changes a width (Tabs and panes):

  1. Names in full first.
  2. When they don't fit, the longest give way first: the water level falls and short names stay whole. Every tab is at most 200px (120px title only) and goes down to 80px (48px title only).
  3. Only when every tab is at its least width and they still don't fit does All tabs appear. Its room is kept first, then the pinned tabs are placed, then the tabs in order, each at a readable width (up to 120px, 72px title only); the rest move into the list whole, never half shown.
  4. The front tab is never in the list. When it would be, it takes the place of the last tabs kept, at the width any tab has there, never one of its own: choosing a tab from All tabs brings it into the bar that way. A bar too short even for that gives it the room left beside All tabs, never under 56px. One tab never moves into the list: it is cut.
tab-bar/compositions/fit

The rule is fitTabs, a pure function the bar runs on what it measures, so it is tested without a browser. It reads only the tabs' names and the bar's width; which tab is in front only keeps that tab out of the list. Each tab keeps the ×'s room whether its × shows or not (a background tab's shows on hover in it), and the front tab keeps the others' weight, so nothing about a tab changes its width when it comes to the front. The bar measures every tab whole, unshrunk and uncapped, so the measurement never depends on the last fit's output. Once All tabs shows, it goes only when the tabs fit with 6px to spare, so a bar whose width sits on the boundary can't flip it on every layout. Should a layout ever chase its own output, All tabs showing and hiding more than 6 times within a second holds it, with the tabs laid out for it, for the rest of that second, and the bar warns once in the console. Web fonts loading fit the tabs again.

All tabs

  • It lists every tab of the pane with its icon and name, the front one checked, then, after a divider, the merged tabs, and after another, the squeezed tabs. Choosing one brings it to the front, back into the bar (a squeezed one goes to onValueChange, for the app to restore with). Its heading counts the pane's own tabs; its name counts every tab it lists.
  • A hidden tab with something new puts one attention dot on the button, and its own count or dot on its item.
  • In a compact bar (density="compact", a pane under 280px) every tab shows its title alone, the front one too, and the button shows the count and its chevron, never a bare chevron. Its name stays its tooltip and accessible name.
tab-bar/compositions/narrow

Merged and squeezed tabs

Other panes' tabs join a bar after a divider in two cases, and each has its own slot, since the tabs behave differently in each.

  • Merged (merged): at a narrow window's last step the rightmost column's tabs join its left neighbour's top bar (Tabs and panes). They are the bar's tabs as much as its own are, plain Tabs with nothing extra: the same width rule, in the same fit, after its own; those that don't fit go into All tabs, after the same divider there. Any of them can be the bar's value, and each has its ×, middle click, Delete, its menu and its drag, as its own tabs have. The divider shows only between tabs: when every merged tab, or every own one, is in All tabs, it goes too. A drop among them is a drop into their own pane, so it has an index of its own: mergedInsertAt draws the line among the merged tabs, as insertAt does among the bar's own.
tab-bar/compositions/merged
  • Squeezed (squeezed, each Tab with squeezed): while this pane is maximized, every other pane's tabs, dimmed. The pane's own tabs are fitted first, exactly as in a bar with none, and the squeezed tabs get only the room they leave, never the reverse: the maximized pane is what the person works in. In that room the same width rule holds (names in full, the longest giving way first) down to 56px, the floor every tab has; then the last ones move into All tabs, whole, listed after a divider below the bar's own and merged tabs, and the divider in the bar goes with the last of them. All tabs' room comes off the bar before the own tabs are fitted again: that button's width, beside the squeezed tabs' divider, is all the own tabs ever give up for them. As for the own tabs, once All tabs shows it goes only when the squeezed tabs fit with 6px to spare. They never come to the front and have no ×; a tab's menu still opens on a right-click, so any tab has its menu. Choosing one, in the bar or in All tabs, comes to onValueChange, for the app to restore the layout with and show it in its own pane.
  • Maximize shows while onToggleMaximize is given; while maximized it is pressed and named Restore, an icon like Maximize, never a labelled button. onEmptyDoubleClick runs on a double click on the bar's empty part.
tab-bar/compositions/maximized

Content

  • Name the tablist after its pane, or "Tabs". Pass translations as messages; tooltips can carry the app's shortcut, such as "New tab (⌘T)".
  • All tabs reads each tab's own props: its value, its prefix and title as its name (a task's reference and title, an App's name), or a web page's pageTitle (its title, the domain, while it has none), its icon, unread and unreadDot. A component wrapping Tab passes these on as its own props, so All tabs follows them as they change; a Tab whose wrapper doesn't is still listed, from what the Tab says itself.

Accessibility

  • The tabs are one tablist, one Tab stop: the arrow keys move between them in order, its own then the merged or squeezed ones, past the divider (Tab). Tab then reaches All tabs, +, and Maximize or Restore.
  • The + button is named New tab, ⤢ Maximize, and ⤡ Restore while pressed (its tooltip says so too). All tabs is named with its count, and says when a hidden tab has something new: "All tabs (6), new in hidden tabs".
  • The bar's dividers and the insertion line are hidden from assistive technology; in All tabs the divider is the menu's separator.
  • The bar registers no shortcuts: ⌘T, ⌘W, ⌃Tab, ⌘↩ and Escape are the app's, through onNewTab, onToggleMaximize and the tabs' onClose.

Rules

  • Keep the bar's end to +, Maximize and, only when needed, All tabs. Never a ⋯.
  • Fit the tabs by the width rule only; never cap the number of tabs or close one for the person.
  • Show All tabs only when every tab is at its least width and they still don't fit, or, while maximized, when the squeezed tabs don't fit at 56px in the room the pane's own tabs leave.
  • Never narrow a maximized pane's own tabs for its squeezed ones beyond All tabs' room and the divider's.

API

TabBar

ExperimentalA pane's first row: its tabs (`Tabs` › `TabsList`), then at its end only + and Maximize (pressed, as Restore, while maximized), with All tabs before them while the tabs don't fit. What is done to a tab or its pane is in the tab's own menu; the bar has no ⋯.
PropTypeDefault
children (required)The pane's `Tab`s, pinned ones first. All tabs lists them from their props (`value`, `prefix` and `title`, `icon`, `unread`, `unreadDot`), or, for a Tab inside a wrapper that doesn't pass them on, from the Tab itself.ReactNode
density`compact`, for a pane under 280px: every tab shows its title alone, in front or not (no icon; its × laid over the title's end, the front tab's always, another's on hover), and All tabs its count and chevron (its name stays its tooltip and accessible name)."compact" | "regular""regular"
insertAtA tab is being dropped into this bar before the tab at this index of its `children` (their count puts it at the end of them, before the divider): a line in the gap the tabs open. `null` for no drop here.numbernull
label (required)The tab list's accessible name: the pane's name, or "Tabs".string
maximizedbooleanfalse
mergedThe `Tab`s of the column merged into this pane in a narrow window, after a divider. They are the bar's tabs as much as its `children` are: the same width rule and fit, All tabs (after the same divider), any of them the bar's `value`, each with its ×, menu and drag.ReactNode
mergedInsertAtThe same for the `merged` tabs: a drop into the merged column, before its tab at this index (their count puts it at the end). An index of its own, as the merged tabs are another pane's. `insertAt` wins if both are given.numbernull
messagesPartial<TabBarMessages>
onEmptyDoubleClickA double click on the bar's empty part: maximize or restore.() => void
onNewTabThe + button: a new tab. Without it there is no +.() => void
onToggleMaximizeThe Maximize button, and Restore while maximized. Without it neither shows.() => void
onValueChange (required)(value: string) => void
squeezedEvery other pane's tabs while this one is maximized, after a divider (`Tab` with `squeezed`): dimmed, never in front, given only the room the bar's own tabs leave (they give way first, then move into All tabs, after a divider). Choosing one comes to `onValueChange`, for the app to restore the layout with.ReactNode
value (required)The front tab's value: the `Tab` with this value is in front.string

Also takes the attributes of its element.