Tabs

Switch between panels, or between views of the same data.

Website refresh ships on December 12. 14 of 22 issues are done.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/tabs

Usage

import { Tabs } from "./ui/uicontext/components/kit/Tabs.ts"
const Tab = Schema.Literals(["activity", "comments"])const Message = UiSchema.TaggedEnum({ SelectedTab: { tab: Tab } })// `tab` lives in your Model; SelectedTab sets itexport const IssueTabs = (h: Html.H<typeof Message.Type>, tab: typeof Tab.Type) =>	Tabs(h, {		label: "Issue",		value: tab,		items: [			{ value: "activity", label: "Activity" },			{ value: "comments", label: "Comments" },		],		onSelect: (tab) => Message.SelectedTab({ tab }),		panel: (tab) => h.p.children(tab === "activity" ? "Grace moved this to In Review." : "No comments yet."),	})

Examples

Filters over one list

With panelMode: "shared" every tab drives the same panel, for views of the same data. A disabled tab stays visible.

  • Draft the Q3 launch emailJul 8
  • Review the pricing page copyJul 9

More tabs than room

The row scrolls sideways and fades at the edge that hides more. The selected tab stays in view, whether a click, the arrow keys or the app picked it.

Secrets: the Invoice sync workflow

API reference

Options

Tabs options
NameTypeDescription
labelrequiredstringThe tab list's accessible name: "Views".
valuerequiredstring | nullThe selected tab's value, or null for none. The caller keeps it.
itemsrequiredTabItem<string>[]The tabs, each with a value, a label and an optional glyph.
onSelectrequired(value: string) => MessageThe message for a tab the person selected, by click or arrow keys.
panelrequired(value: string) => View.InputDraws the panel for a tab's value.
panelMode"shared"shared keeps one panel mounted across tabs, for tabs that change the data of one continuing view; otherwise each tab has its own panel.
actionsView.InputControls at the end of the tab row, such as a filter or a New button.
beforePanelsView.InputContent between the tab row and the panels, such as a toolbar.
styleStyleStyleX styles for the root.
toolbarStyleStyleStyleX styles for the row that holds the tabs and actions.
listStyleStyleStyleX styles for the tab list.
tabStyleStyleStyleX styles for every tab.
currentStyleStyleStyleX styles for the selected tab, applied last.

Accessibility

  • Follows the tabs pattern: arrow keys move between tabs, Home and End jump to the ends, Enter or Space selects.
  • Each panel is labelled by its tab. Set keepMounted on a tab whose panel holds unsaved input.

Source