packages/react-components/react-tabs/library/docs/Spec.md
GitHub Epic issue - Tabs/Pivot Convergence #20338 Figma - Tabs
Tabs allow for navigation between two or more content views and relies on text headers to articulate the different sections of content.
There are a few different components typically provided for tabs:
In some cases the tab list and tab panels are provided together in a "tabs" aggregate component. This is historically done to provide the manilla folder tab style where the tab list and tab panels are arranged next to each other.
Naming: The Open UI component naming matrix indicates Tabs is the most common and popular name for this component. Only Fabric/Fluent UI v8 and earlier named it Pivot.
The Tabs Research notes part naming and terminology are not very consistent across libraries.
The API and implementations depend on how tabs are conceptualized and integrated with existing components. For example, a set of tabs can be thought of as:
Features common to most libraries:
Features common to some libraries:
Advanced features supported by only a few libraries:
Given the ARIA standard roles of tablist and tab we can follow with TabList and Tab components.
The existing components are:
v0 Menu provides tabs, toolbars, menus, and breadcrumbs. v0 Menu supports tabs interaction when accessibility={tabListBehavior}
v8 provides a separate Pivot component with tabs behavior and appearance customization.
A 'Pivot' appears as a horizontal set of borderless buttons with an underline indicating current selection.
v0 and v8 provide a 'Pivot' appearance. v0: underlined=true v8: by default
A 'Block Tab' appears as a horizontal set of borderless buttons. The selection has an active color, rectangular background.
Both v0 and v8 provide the 'Block Tab' appearance. v0: by default v8: linkFormat="tabs"
v0 supports decorating tabs with arrows pointing toward the associated content. v0: pointing=true
v8 supports a large tab style with increased padding per tab. v8: linkSize="large"
Both v0 and v8 support text, icon, and text and icon as tab content. v0 additionally supports menus as tab content.
Both v0 and v8 support custom rendering of tab content through a render props per item.
v0 does not provide a tab panel since it is implemented through the menu component. v8 supports the tab panel as the children of PivotItem. The tab content is provided through the header property.
By default tabs are arranged horizontally. Content within the tab is arranged horizontally. It is centered (horizontally and vertically). The default appearance is transparent.
<TabList>
<Tab value="tab1">One</Tab>
<Tab value="tab2">Two</Tab>
<Tab value="tab3">Three</Tab>
</TabList>
The vertical prop causes the tabs to be arranged vertically. Content within the tab is still arranged horizontally and centered.
<TabList vertical>
<Tab value="tab1">One</Tab>
<Tab value="tab2">Two</Tab>
<Tab value="tab3">Three</Tab>
</TabList>
The verticalTabContent prop causes the content within the tab to be arranged vertically. The content is still centered. If the icon prop is set, the rendered icon is part of the vertical tab content.
<TabList verticalTabContent>
<Tab value="tab1">One</Tab>
<Tab value="tab2">Two</Tab>
<Tab value="tab3">Three</Tab>
</TabList>
<TabList vertical verticalTabContent>
<Tab value="tab1">One</Tab>
<Tab value="tab2">Two</Tab>
<Tab value="tab3">Three</Tab>
</TabList>
The default appearance is transparent. Transparent has no border and background styles. The selection indicator is a brand color line below the tab. Hovering over a tab shows a gray line below the tab.
<TabList>
</TabList>
<TabList appearance="transparent">
</TabList>
The subtle appearance is similar to transparent, but a light background is displayed when hovering over a tab.
<TabList appearance="subtle"></TabList>
Small and medium sizes are supported. The size affects the padding and spacing between elements. Size can also affect the default icon (and badge) size. The default size is medium.
<TabList size="small">
</TabList>
<TabList size="medium">
</TabList>
When the icon slot is filled, an icon is positioned before the tab content.
<TabList>
<Tab icon={<CheckboxComposite />} value="allowed">
Allowed
</Tab>
<Tab icon={<BlockedSite />} value="blocked">
Blocked
</Tab>
</TabList>
An icon only tab is displayed when the icon slot is filled and tab content is omitted.
<TabList>
<Tab icon={<CheckboxComposite />} value="allowed" />
<Tab icon={<BlockedSite />} value="blocked" />
</TabList>
See API at Tab.types.ts.
Notes:
TabCommons.value supports an arbitrary identifier value. This is similar to Accordion's selection approach.icon slot.See API at TabList.types.ts.
Notes:
root slot.appearance, size, and layout.selectedValue and is expected to call selectTab when clicked.TabProps we could allow individual tabs to override these values. However the expectation is that the tabs within a tab list have a consistent layout and appearance.<TabList>
<Tab>One</Tab>
<Tab>Two</Tab>
<Tab>Three</Tab>
</TabList>
<div role="tablist">
<div role="tab">One</div>
<div role="tab">Two</div>
<div role="tab">Three</div>
</div>
See MIGRATION.md.
TabList provides single selection of a tab.
The TabList.selectedKey can control the currently selected tab. The onTabSelected event informs callers of a selection change. The event data includes the tab value.
Clicking the tab selects it.
The tab list will support the prescribed ARIA keyboard interaction.
A Tablist allows focus of individual tabs.
When the TabList has focus, the user can use arrow keys to move focus to the next or previous tab. The keys are based on layout. Horizontal uses left/right arrows and vertical uses up/down arrows.
When the TabList has focus, the user can use the home/end keys to move focus to the first/last tab.
A tab is selected when the spacebar/enter key is pressed for a focused tab.
The TAB key moves focus out of the tabs.
ARIA provides tab-specific roles:
TabList and Tab will apply the tablist and tab ARIA roles.
The tabpanel will be reserved for possible future component.
Screen readers will read each tab's content.
The design spec details a menu button (...) that displays the list of tabs that were not able to be displayed due to limited space. We have some concerns providing overflow as a default feature of tabs. The v1 of TabList and Tab will not include overflow.
The design spec shows a badge which is arranged near the icon or text. The initial vNext package will not provide a badge variant or badge slot.
The intial work to explore supporting a badge used a BadgeTab variant.
While the design spec does not cover tab panels, v8 Pivot supports them through the content of the PivotItem. They are also a common scenario when the tabs are adjacent to the content associated with each tab.
If/When we do support tab panels,