Tabs

A compound component for switching between related panels of content, with a sliding active-tab indicator.

Installation

npx dafink-ui add tabs

Demo

Manage your account settings and preferences.

Composition

<Tabs>
<TabsList>
<TabsTrigger />
</TabsList>
<TabsContent />
</Tabs>

Props

NameTypeDefaultDescription
valuestring-The currently active tab value (controlled).
onValueChange(v: string) => void-Called when the user activates a different tab.
classNamestring""Additional classes on the root wrapper div.

Accessibility

Tabs uses roving tabindex: only the active trigger sits in the page's Tab order, so Tab moves into and out of the whole tab list in a single stop, the same mechanic as ToggleGroup and MenuBarNav. Arrow keys move focus between triggers without changing the active tab; Enter/Space activates whichever trigger is currently focused. TabsList carries role="tablist", each trigger carries role="tab" with aria-selected and aria-controls pointing at its panel, and each TabsContent carries role="tabpanel" with aria-labelledby pointing back to its trigger; the inactive panel is unmounted entirely rather than merely hidden.

KeyFunction
tabMoves focus to the tab list's active trigger, or out to the next tabbable element if focus is already inside the list.
shift+tabMoves focus out of the tab list to the previous tabbable element.
right arrowMoves focus to the next enabled trigger, wrapping from the last to the first.
left arrowMoves focus to the previous enabled trigger, wrapping from the first to the last.
homeMoves focus to the first enabled trigger.
endMoves focus to the last enabled trigger.
enterActivates the focused trigger.
spaceActivates the focused trigger.