Tab Group
<wa-tab-group>
Tab groups organize related content into a single container that displays one panel at a time, with tabs for switching between them.
Tab groups make use of tabs and tab panels. Each panel should have a name that's unique within the tab group, and tabs should have a panel attribute that points to the respective panel's name.
Examples
Setting the Active Tab
To make a tab active, set the active attribute to the name of the appropriate panel.
Tabs on Bottom
Tabs can be shown on the bottom by setting placement to bottom.
Tabs on Start
Tabs can be shown on the starting side by setting placement to start.
Tabs on End
Tabs can be shown on the ending side by setting placement to end.
Closable Tabs
You can make a tab closable by adding a close button next to the tab and inside the nav slot. You can position the button to your liking with CSS and handle close/restore behaviors by removing/appending the tab as desired. Note the use of tabindex="-1", which prevents the close button from interfering with the tab order. The close button is still recognizable to the virtual cursor in screen readers.
Scrolling Tabs
When there are more tabs than horizontal space allows, the nav will be scrollable.
Manual Activation
When focused, keyboard users can press Left or Right to select the desired tab. By default, the corresponding tab panel will be shown immediately (automatic activation). You can change this behavior by setting activation="manual" which will require the user to press Space or Enter before showing the tab panel (manual activation).
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/[email protected]/components/tab-group/tab-group.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/tab-group/tab-group.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/tab-group/tab-group.js';
To import this component for React 18 or below, use the following code:
import WaTabGroup from '@awesome.me/webawesome/dist/react/tab-group/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | Used for grouping tab panels in the tab group. Must be <wa-tab-panel> elements. |
nav
|
Used for grouping tabs in the tab group. Must be <wa-tab> elements. Note that <wa-tab> will set this slot on itself automatically. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
activationactivation |
When set to auto, navigating tabs with the arrow keys will instantly show the corresponding tab panel. When set to
manual, the tab will receive focus but will not show until the user presses spacebar or enter.
Type
'auto' | 'manual'Default
'auto' |
||
activeactive |
Sets the active tab.
Type
stringDefault
'' |
|
|
css |
One or more CSSResultGroup to include in the component's shadow root. Host styles are automatically prepended.
Type
CSSResultGroup | undefinedDefault
styles |
||
defaultSlot |
Default slot for
<wa-tab-panel> children (inside the body part container).Type
HTMLSlotElement |
||
placementplacement |
The placement of the tabs.
Type
'top' | 'bottom' | 'start' | 'end'Default
'top' |
||
withoutScrollControlswithout-scroll-controls |
Disables the scroll arrows that appear when tabs overflow.
Type
booleanDefault
false |
Events
Learn more about events.
| Name | Description |
|---|---|
wa-tab-hide |
Emitted when a tab is hidden. |
wa-tab-show |
Emitted when a tab is shown. |
CSS custom properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--indicator-color |
The color of the active tab indicator.
|
--track-color |
The color of the indicator's track (the line that separates tabs from panels).
|
--track-width |
The width of the indicator's track (the line that separates tabs from panels).
|
CSS parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
base |
The component's base wrapper. |
::part(base)
|
body |
The tab group's body where tab panels are slotted in. |
::part(body)
|
nav |
The tab group's navigation container where tabs are slotted in. |
::part(nav)
|
scroll-button |
The previous/next scroll buttons that show when tabs are scrollable, a <wa-button>. |
::part(scroll-button)
|
scroll-button__base |
The scroll button's exported base part. |
::part(scroll-button__base)
|
scroll-button-end |
The ending scroll button. |
::part(scroll-button-end)
|
scroll-button-start |
The starting scroll button. |
::part(scroll-button-start)
|
tabs |
The container that wraps the tabs. |
::part(tabs)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.