Fragiola

API: components

Tabs

Layered sections of content, one visible at a time, chosen from a tab list with the APG keyboard - arrow keys, Home and End, automatic or manual activation.

Layered sections of content, one shown at a time, chosen from a list of tabs. It follows the WAI-ARIA APG tabs pattern.

Settings tabs
Gallery

Behaviour

  • Roving focus: the tab list is one tab stop (the selected tab, else the first); the arrow keys move between tabs, Home and End jump to the first and last, wrapping when loopFocus.
  • Activation: automatic (the default, the APG's recommendation when a panel shows without delay) selects the tab focus moves to (reason list-navigation); manual waits for Enter or Space. A click selects and focuses (reason trigger-press).
  • Disabled tabs stay focusable, so they can be discovered, but are never selected.
  • Panels: Tab moves from the tab list to the selected panel, which is a tab stop of its own. An inactive panel is not rendered, unless keepMounted keeps it, hidden.
  • Panel transitions: a newly selected panel enters with data-starting-style, the previous one exits with data-ending-style (and inert) before it unmounts; data-activation-direction tells a recipe which side to slide from.
  • Indicator: it exposes the selected tab's box, relative to the list, as CSS variables, for a line that follows the selection.
  • RTL: in a horizontal list, ArrowRight and ArrowLeft swap.

Anatomy

partelementdata-primitives-partrole
Rootdivtabs-rootholds the state
Listdivtabs-listthe tablist
Tabbuttontabs-taba tab
Indicatorspantabs-indicatorfollows the selected tab (optional)
Paneldivtabs-panela tabpanel

Usage

import { Tabs } from "@fragiola/primitives-react/tabs";

<Tabs.Root defaultValue="account">
    <Tabs.List aria-label="Account settings">
        <Tabs.Tab value="account">Account</Tabs.Tab>
        <Tabs.Tab value="password">Password</Tabs.Tab>
        <Tabs.Indicator />
    </Tabs.List>
    <Tabs.Panel value="account">Your account.</Tabs.Panel>
    <Tabs.Panel value="password">Your password.</Tabs.Panel>
</Tabs.Root>;

Props

Every part also takes what the primitive contract gives. The names below are React's; Vue binds them as v-model:value and @value-change, Angular as [(value)] and (valueChangeDetails).

Root

proptypedefaultdescription
valuestringthe selected tab, controlled
defaultValuestringthe first enabled tabthe initial selection, uncontrolled
onValueChange(value: string, details: { reason }) => voidevery change, with its reason (list-navigation, trigger-press)
orientation"horizontal" | "vertical""horizontal"which arrow keys move between tabs
activation"automatic" | "manual""automatic"whether focus selects, or Enter and Space do
loopFocusbooleantruewhether the arrow keys wrap around

List

No props of its own. Give it an accessible name (aria-label or aria-labelledby).

Tab

proptypedefaultdescription
valuestringrequired: the tab's value, matching its panel
disabledbooleanfalsefocusable, never selected

Indicator

It sets the logical --tabs-indicator-inset-inline-start, --tabs-indicator-inset-block-start, --tabs-indicator-inline-size and --tabs-indicator-block-size, and the physical --active-tab-left, --active-tab-right, --active-tab-top, --active-tab-bottom, --active-tab-width and --active-tab-height (Base UI's names), and is not rendered while no tab is selected (Angular's *tabsIndicator is structural).

proptypedefaultdescription
renderBeforeHydrationbooleanfalsein a server render, places it before hydration: a small inline script inside it measures the selected tab as the page parses, then removes itself (Server rendering) (Angular: *tabsIndicator="true")
noncestringthe nonce of that script, so it runs under a Content Security Policy that allows inline scripts by nonce (Angular: *tabsIndicator="true; nonce: cspNonce", else Angular's CSP_NONCE provider)

Panel

proptypedefaultdescription
valuestringrequired: the value of its tab (Angular: *tabsPanel="value")
keepMountedbooleanfalsekeep an inactive panel rendered, hidden once its exit ended

State and part attributes

partattributes
Rootdata-orientation, data-activation, data-activation-direction
Listrole="tablist", aria-orientation, data-orientation, data-activation-direction
Tabrole="tab", aria-selected, aria-controls, tabindex, aria-disabled and data-disabled when disabled, data-selected, data-orientation, data-activation-direction
Indicatoraria-hidden="true", data-orientation, data-activation-direction
Panelrole="tabpanel", aria-labelledby, tabindex="0", data-selected, data-starting-style / data-ending-style, inert while it exits, hidden when kept mounted and inactive, data-orientation, data-activation-direction

data-activation-direction is where the newly selected tab sits from the previous one: left, right, up, down, or none before any change. It is physical, as the Indicator's travel: in RTL the next tab is on the left. A panel that becomes selected renders with data-starting-style for a frame (not on the first render); one that stops being selected stays, inert, with data-ending-style until its animations end. Two panels exist together while one exits: stack them in one grid cell, or animate the enter only.

Keyboard

keyhorizontalvertical
next tabArrowRight (ArrowLeft in RTL)ArrowDown
previous tabArrowLeft (ArrowRight in RTL)ArrowUp
Home, Endthe first, the last tabthe same
Enter, Spaceselects the focused tab (manual)the same
Tabfrom the tab list to the selected panelthe same

Exports

entryexports
@fragiola/primitives-react/tabsTabs, TabsRootProps, TabsRootState, TabsTabProps, TabsTabState, TabsIndicatorProps, TabsPanelProps, TabsPanelState, ActivationDirection, ChangeDetails, ChangeReason, RenderProp
@fragiola/primitives-vue/tabsTabs, TabsRootProps, TabsRootEmits, TabsRootState, TabsListState, TabsTabProps, TabsTabState, TabsIndicatorProps, TabsIndicatorState, TabsPanelProps, TabsPanelState, ActivationDirection, ChangeDetails, ChangeReason, RenderSlotProps
@fragiola/primitives-angular/tabsTabsRoot, TabsList, TabsTab, TabsIndicator, TabsPanel, injectTabs, TabInfo, TabsRootState, TabsTabState, TabsIndicatorState, TabsPanelState, ActivationDirection, ChangeDetails, ChangeReason, ValueChangeEvent