Tab Strip

Document tabs over the page: open, close, drag to reorder, and every tab one press away when they overflow.

Overview

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/tab-strip

Usage

import { closeTab, moveTab, type StripTab, TabStrip } from "./ui/uicontext/components/kit/TabStrip.ts"
type Model = { readonly tabs: ReadonlyArray<StripTab>; readonly current: string | null }// the app keeps the tabs; `closeTab` also picks the tab to show nextexport const Tabs = <M>(h: Html.H<M>, model: Model, changed: (next: Model) => M) =>	TabStrip(h, {		props: { label: "Open tabs", tabs: model.tabs, current: model.current },		onEmit: {			RequestedSelect: ({ id }) => changed({ ...model, current: id }),			RequestedClose: ({ id }) => changed(closeTab(model.tabs, id, model.current)),			RequestedMove: ({ id, index }) => changed({ ...model, tabs: moveTab(model.tabs, id, index) }),			RequestedNew: () => undefined,		},	})

API reference

Props

TabStrip props
NameTypeDescription
labelrequiredstringThe tab list's accessible name: "Open tabs"
tabsrequiredStripTab[]—
currentrequiredstring | nullThe shown tab's id
addLabelstringA + button at the end that asks for a new tab, named by this: "New tab"
agentIdstring—

Events

TabStrip events
EventPayloadDescription
RequestedSelect{ id: string }Show this tab: set current
RequestedClose{ id: string }Close this tab: drop it, and if it was shown, show closeTab's next
RequestedMove{ id: string; index: number }Move this tab to index in the new order
RequestedNew{}The + button

Agent actions

What agents can do with TabStrip
ActionDescription
RequestedSelectShow a tab, by id
RequestedCloseClose a tab, by id
RequestedMoveMove a tab, by id, to an index in the new order

Accessibility

  • A tablist with one Tab stop on the open tab: Left and Right move, Home and End jump, Enter or Space shows the focused tab, Delete closes it and Alt+Shift with the arrows moves it.
  • Each × is named for its tab (“Close Billing”) and left out of the Tab order, since Delete does the same; a tab with unsaved changes reads “(edited)”.
  • Agents read the tabs and show, close or move one by id.

Source