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.
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).
When to use
Anatomy
- The tab area:
Tabs›TabsList, named bylabel, holding thechildren(the pane's tabs, pinned ones first; the workspace tabs pin none for now, Tabs and panes), then a divider and themergedtabs in a narrow window, or a divider and thesqueezedtabs while the pane is maximized (Merged and squeezed tabs). The tab whosevalueis the bar'svalueis in front; the bar'sdensityreaches every tab. - All tabs: a ghost Button opening a DropdownMenu of every tab in
children, then a divider and every tab inmerged, then a divider and every tab insqueezed, the front one checked. Only while the tabs don't fit. - The + button (
onNewTab) and Maximize (onToggleMaximize): PanelActions with tooltips. Maximize is aPanelToggleAction: pressed whilemaximized, withminimize-2and 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):
- Names in full first.
- 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).
- 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.
- 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.
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
compactbar (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.
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, plainTabs 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'svalue, 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:mergedInsertAtdraws the line among the merged tabs, asinsertAtdoes among the bar's own.
- Squeezed (
squeezed, eachTabwithsqueezed): 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'smenustill opens on a right-click, so any tab has its menu. Choosing one, in the bar or in All tabs, comes toonValueChange, for the app to restore the layout with and show it in its own pane. - Maximize shows while
onToggleMaximizeis given; whilemaximizedit is pressed and named Restore, an icon like Maximize, never a labelled button.onEmptyDoubleClickruns on a double click on the bar's empty part.
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, itsprefixandtitleas its name (a task's reference and title, an App's name), or a web page'spageTitle(itstitle, the domain, while it has none), itsicon,unreadandunreadDot. A component wrappingTabpasses 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,onToggleMaximizeand 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
Also takes the attributes of its element.