Back to Fluentui

Tabs

packages/web-components/src/tabs/tabs.spec.md

4.40.2-hotfix214.0 KB
Original Source

Tabs

Description

Tabs allow for navigation between two or more content views and relies on text headers to articulate the different sections of content.

A note on the naming of this component. The closest equivalent from Fluent UI React is the TabList control. The Web Component Tabs control is named differently because the control comprises of Tabs, Tab List and a Tab Panel. Whereas the react equivalent does not include tab panels. Therefore, a fully equivalent name, in this case, would be inaccurate.

Design Spec

Link to Design Spec in Figma

Engineering Spec

Inputs

attributetypedefaultdescription
activeidstring-sets the selected tab
appearance"subtle" | "transparent"transparent"-
disabledboolean-blocks control and all tab children from all keyboard and mouse events.
size"small" | "medium" | "large""medium"
orientation"vertical" | "horizontal""horizontal"sets the orientation of the tab list to vertical display

Outputs

  • [selectedValue: unkown] - the selected value of the currently selected tab

Events

  • change: html event handler - event fires on keyboard or mouse click

Slots

  • start - content before the tab list
  • end - content after the tab list
  • tab - slot for the tab itself
  • tabpanel - slot for tab panel

CSS Variables

statevariantdestinationcss variable
resttransparent, rest, selectedbackground color--transparentBackground
resttransparent, rest, selectedcontent color--neutralForeground1
resttransparent, rest, selectedselection indicator color--compoundBrandStroke1
resttransparent, rest, selectedicon color--compoundBrandForeground1
-------
resttransparent, rest, unselectedbackground color--transparentBackground
resttransparent, rest, unselectedcontent color--neutralForeground2
resttransparent, rest, unselectedselection indicator color--transparentStroke
resttransparent, rest, unselectedicon color--neutralForeground2
--------
hovertransparent, hover, selectedbackground color--transparentBackgroundHover
hovertransparent, hover, selectedcontent color--neutralForeground1Hover
hovertransparent, hover, selectedselection indicator color--compoundBrandStroke1Hover
hovertransparent, hover, selectedicon color--compoundBrandForeground1Hover
--------
hovertransparent, hover, unselectedbackground color--transparentBackgroundHover
hovertransparent, hover, unselectedcontent color--neutralForeground2Hover
hovertransparent, hover, unselectedselection indicator color--compoundBrandStroke1Hover
hovertransparent, hover, unselectedicon color--compoundBrandForeground2Hover
--------
pressedtransparent, hover, selectedbackground color--transparentBackgroundPressed
pressedtransparent, hover, selectedcontent color--neutralForeground1Pressed
pressedtransparent, hover, selectedselection indicator color--compoundBrandStroke1Pressed
pressedtransparent, hover, selectedicon color--compoundBrandForeground1Pressed
--------
pressedtransparent, hover, unselectedbackground color--transparentBackgroundPressed
pressedtransparent, hover, unselectedcontent color--neutralForeground2Pressed
pressedtransparent, hover, unselectedselection indicator color--neutralStroke1Pressed
pressedtransparent, hover, unselectedicon color--compoundBrandForeground1Pressed
--------
disabledtransparent, disabled, selectedbackground color--transparentBackground
disabledtransparent, disabled, selectedcontent color--neutralForegroundDisabled
disabledtransparent, disabled, selectedselection indicator color--neutralForegroundDisabled
disabledtransparent, disabled, selectedicon color--nuetralForegroundDisabled
--------
disabledtransparent, disabled, unselectedbackground color--transparentBackground
disabledtransparent, disabled, unselectedcontent color--neutralForegroundDisabled
disabledtransparent, disabled, unselectedselection indicator color--transparentStroke
disabledtransparent, disabled, unselectedicon color--neutralForegroundDisabled

Accessibility

  • Tabs WCAG's patterns: https://www.w3.org/WAI/ARIA/apg/patterns/tabs/
    • recommended that tabs activate on focus
    • content of table is preloaded
    • when tab list is aria-orientation vertical: down arrow performs as right arrow and up arrow performs as left arrow
    • Horizontal tab list does not listen for down arrow or up arrow
    • when tabpanel does not contain any focusable elements or the first element is not focusable the tab panel should set tabindex="0"
  • Are there any accessibility elements unique to this component? yes, many see link above.
  • List ARIA attributes: role, aria-labelledby, aria-label, aria-controls, aria-selected, aria-haspopup, aria-orientation
  • Does the component support 400% zoom?

Preparation

Differences from Fluent UI to FAST

The Fluent/FAST web component differs from the Fluent React Control as follows:

differenceTabs - Fluent Web ComponentTabList - Fluent React Component
active indicator control / id control selectionmanaged by controlmanaged by user with application state
keyboard and focus selectionselects active tab on arrow key focus changereselects tab on space bar or enter after arrow refocus
icon slottingfavors composition (dev chooses how to slot which icon)favors automation (dev supplies icon name and control handles the rendering of icon)
icon slotting filled / unfilled iconsfavors composition over automated handling. requires dev to add interactivity to render filled or unfilled iconfavors automated handling of icons and provides filled and unfilled iconography on selection
tab-panelsrequires tab panel control to set content on tab selectiondoes not require or include a tab panel control / template
reserve-selected-tab-spacehas reserve selected tab space defaulting to true and gives user the option to set to falseremoves attribute

Link to FAST Web Component API

fluent api namefast api Equivalent
verticalorientation
selected-valueactiveid
valueid

Implementation - Sample Code

Default

By default Tabs are arranged horizontally. The developer sets selected-value Fluent-Tab-List attribute. The Component handles the logic of what is shown and hidden when user clicks on the tabs. For switcing to work correctly the tab list requires that the indexing of the tabs and tab-panels be organized to correspond to their matching items - the order of the tabs must match the order of the tab panels:

html
<fluent-tab-list>
  <fluent-tab>One / Left</fluent-tab>
  <fluent-tab>Two / Middle</fluent-tab>
  <fluent-tab>Three / Right</fluent-tab>

  <fluent-tab-panel>Panel One</fluent-tab-panel>
  <fluent-tab-panel>Panel Two</fluent-tab-panel>
  <fluent-tab-panel>Panel Three</fluent-tab-panel>
</fluent-tab-list>

Controlled

If the developer wants to control the selected tab, tab values can be provided.

html
<fluent-tab-list activeid="tab-one">
  <fluent-tab id="tab-one">One / Left</fluent-tab>
  <fluent-tab id="tab-two">Two / Middle</fluent-tab>
  <fluent-tab id="tab-three">Three / Right</fluent-tab>

  <fluent-tab-panel>Panel One</fluent-tab-panel>
  <fluent-tab-panel>Panel Two</fluent-tab-panel>
  <fluent-tab-panel>Panel Three</fluent-tab-panel>
</fluent-tab-list>

Vertical

html
<fluent-tab-list orientation="vertical">
  <fluent-tab>One / Left</fluent-tab>
  <fluent-tab>Two / Middle</fluent-tab>
  <fluent-tab>Three / Right</fluent-tab>
</fluent-tab-list>

Implementation

Validation