Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Tab Strip

PreviousNext

Document tabs, as in a browser or an editor. Pin, preview, drag to reorder, close, reopen and rename.

app-shell.tsx

Tab Strip shows the documents a person has open: pages, files, sessions, anything your app opens side by side. The tabs are your data: pass the active one as value and update it in onValueChange. useTabStripState keeps that data for you, with pinned and preview tabs, the most recent tab, and a reopen stack.

The active tab's pill slides from tab to tab, and a hover highlight glides along the strip. The close button's slot is always there, so titles never reflow when it appears.

Tab Strip is part of the Fabricator style. Inside an App Shell it also registers the usual tab shortcuts.

Installation

bunx --bun fabricator-ui@latest add tab-strip

Usage

import {
  TabStrip,
  TabStripList,
  TabStripNew,
  TabStripTab,
  useTabStripState,
} from "@/components/ui/tab-strip"
const tabs = useTabStripState({ defaultState })
 
<TabStrip {...tabs.stripProps} onNew={openNew}>
  <TabStripList>
    {tabs.state.tabs.map((id) => (
      <TabStripTab
        key={id}
        value={id}
        icon={docs[id].icon}
        pinned={tabs.state.pinned.includes(id)}
        preview={tabs.state.preview === id}
      >
        {docs[id].title}
      </TabStripTab>
    ))}
  </TabStripList>
  <TabStripNew />
</TabStrip>

stripProps wires value, onValueChange, onClose, onReorder, onPin and onReopen. Keep your own store instead by passing those yourself: each operation is a pure function in lib/app-shell-model.ts (openTab, closeTabs, closeOtherTabs, moveTab, togglePinnedTab, reopenClosedTab…).

Examples

In a workbench

The strip above the content of an App Shell, with the shortcuts on.

In a titlebar

The strip in an AppShellTitlebar row of a desktop window.

Tabs

  • Pinned tabs lead the strip and show only their icon; the title is in a tooltip. Pinned tabs can't be closed from the strip, and Close others and Close all spare them.
  • A preview tab is italic, and the next preview replaces it in place. openTab(state, id, { preview: true }) opens one; opening it again for real keeps it.
  • A new tab page gives way to what opens from it: openTab(state, id, { replace: blankTabId }) opens in that tab's place, as in a browser, without keeping it for reopening. A tab that's already open is shown where it is, and the blank one stays.
  • Status shows loading (a spinner), error (an alert icon), dirty (a dot that turns into the close button on hover) and waiting (a pulsing dot).
  • Closing activates the most recently used tab, as editors do, or the neighbour when there is none. Closed tabs go on a reopen stack of 20.
  • Renaming: with onRename, double-click a tab or press F2; Enter saves and Escape cancels.
  • Moving: drag a tab, press ⌥⇧← / ⌥⇧→, or use Move left and Move right in its menu. Landing inside the pinned run pins a tab; landing past it unpins it.
  • Menus: right-click a tab for Pin, Rename, Move, Close, Close others, Close to the right, Close all and Reopen, followed by the tab's own actions. Right-click the empty strip for New tab and Reopen.
  • Overflow: tabs shrink from 192px to 144px, then the strip scrolls sideways under faded edges and keeps the active tab in view. TabStripNew follows the last tab, and TabStripOverflow adds a menu of every tab at the end of the row. Give the strip min-w-0 flex-1 so it runs the full width of its row.

Shortcuts

Inside an App Shell (shortcuts={false} turns them off). In a browser, the keys the browser keeps get the second column; in a desktop app the first applies.

ActionDesktopBrowser
New tab⌘T⌥⌘T
Close tab⌘W⌥⌘W
Reopen closed tab⇧⌘T⌥⇧⌘T
Next / previous⌃Tab, ⇧⌘] / ⌃⇧Tab, ⇧⌘[⌥⇧] / ⌥⇧[
Tab 1 to 8, last⌘1…⌘8, ⌘9⌥1…⌥8, ⌥9

On Windows and Linux, ⌘ is Ctrl.

Tabs and routes

Tabs are resources, not routes. Keep the URL on the active tab with replace, so the browser's Back walks pages rather than tabs:

React.useEffect(() => {
  if (tabs.activeId) router.replace(hrefFor(tabs.activeId))
}, [tabs.activeId])

API Reference

TabStrip

Also takes the props of a <div>.

PropTypeDefault
valuestring | null-
onValueChange(value: string) => void-
onClose(values: string[]) => void-
onReorder(value: string, index: number) => void-
onPin(value: string, pinned: boolean) => void-
onRename(value: string, title: string) => void-
onReopen() => void-
onNew() => void-
panelIdstring-
size"default" | "sm""default"
shortcutsbooleantrue

Without onClose, tabs have no close button; without onReorder, they don't drag.

TabStripTab

PropTypeDefault
valuestring-
titlestringits text
iconReact.ComponentType-
pinnedbooleanfalse
previewbooleanfalse
status"loading" | "error" | "dirty" | "waiting"-
closablebooleantrue unless pinned
actions{ id, label, icon?, destructive?, separatorBefore?, onSelect }[][]

useTabStripState

OptionTypeDefault
defaultStateTabStripStateno tabs
storageShellStorage-
storageKeystring-

Returns state, activeId, open, activate, close, closeOthers, closeToRight, move, setPinned, reopen and stripProps. With storage and storageKey it saves the strip as app-shell.<storageKey>.tabs.

Data attributes

AttributeElementPresent when
data-slot="tab-strip"rootalways; data-size
data-slot="tab-strip-list"the tab listalways; data-dragging during a drag
data-slot="tab-strip-tab"each tabdata-value, data-active, data-pinned, data-preview, data-status, data-dragging

Accessibility

  • The list is a tablist and each tab a tab with aria-selected. Pass panelId to point the tabs at the content with aria-controls.
  • Only the active tab is in the tab order. ← / → move focus (wrapping), Home and End jump, Enter or Space activates.
  • Delete closes the focused tab (aria-keyshortcuts), F2 renames it, and ⌥⇧← / ⌥⇧→ move it; moves are announced in a live region.
  • The close button is for pointers only and is hidden from assistive tech, so it never sits inside a tab as a second control.
  • Every drag has a menu alternative (Move left, Move right), as WCAG 2.5.7 asks.
  • Middle-click closes a tab without starting the browser's autoscroll.