<cs-tab-group>
StableNavigationSince 0.1

Tab groups organize related content into a single container that displays one panel at a time, with tabs for switching between them.

General Custom Advanced Disabled This is the general tab panel. This is the custom tab panel. This is the advanced tab panel. This is a disabled tab panel.

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

Active Tab

To make a tab active, set the active attribute to the name of the appropriate panel.

General Custom Advanced This is the general tab panel. This is the custom tab panel. This is the advanced tab panel.

Placement

Set the placement attribute to move the tabs to a different edge of the panels.

PlacementTabs appear
top defaultAbove the panels, horizontally
bottomBelow the panels, horizontally
startBefore the panels, stacked vertically
endAfter the panels, stacked vertically
General Custom Advanced Disabled This is the general tab panel. This is the custom tab panel. This is the advanced tab panel. This is a disabled tab panel.
General Custom Advanced Disabled This is the general tab panel. This is the custom tab panel. This is the advanced tab panel. This is a disabled tab panel.

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.

General Closable Advanced This is the general tab panel. This is the closable tab panel. This is the advanced tab panel.
Restore tab

Scrolling Tabs

When there are more tabs than horizontal space allows, the nav will be scrollable.

Tab 1 Tab 2 Tab 3 Tab 4 Tab 5 Tab 6 Tab 7 Tab 8 Tab 9 Tab 10 Tab 11 Tab 12 Tab 13 Tab 14 Tab 15 Tab 16 Tab 17 Tab 18 Tab 19 Tab 20 Tab panel 1 Tab panel 2 Tab panel 3 Tab panel 4 Tab panel 5 Tab panel 6 Tab panel 7 Tab panel 8 Tab panel 9 Tab panel 10 Tab panel 11 Tab panel 12 Tab panel 13 Tab panel 14 Tab panel 15 Tab panel 16 Tab panel 17 Tab panel 18 Tab panel 19 Tab panel 20

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).

General Custom Advanced Disabled This is the general tab panel. This is the custom tab panel. This is the advanced tab panel. This is a disabled tab panel.

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/tab-group/tab-group.js';
import './cornerstone/components/tab-group/tab-group.js';
import CsTabGroup from '@cruglobal/cornerstone-components/react/tab-group/index.js';

Slots

Learn more about using slots.

NameDescription
(default)Used for grouping tab panels in the tab group. Must be <cs-tab-panel> elements.
navUsed for grouping tabs in the tab group. Must be <cs-tab> elements. Note that <cs-tab> will set this slot on itself automatically.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
activationactivationWhen 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.'auto' | 'manual''auto'
activeactiveSets the active tab.string''Yes
defaultSlotDefault slot for <cs-tab-panel> children (inside the body part container).HTMLSlotElement
placementplacementThe placement of the tabs.'top' | 'bottom' | 'start' | 'end''top'
withoutScrollControlswithout-scroll-controlsDisables the scroll arrows that appear when tabs overflow.booleanfalse

Events

Learn more about events.

NameDescription
cs-tab-hideEmitted when a tab is hidden.
cs-tab-showEmitted when a tab is shown.

CSS Custom Properties

Learn more about CSS custom properties.

NameDescriptionDefault
--indicator-colorThe color of the active tab indicator.
--track-colorThe color of the indicator's track (the line that separates tabs from panels).
--track-widthThe width of the indicator's track (the line that separates tabs from panels).

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
bodyThe tab group's body where tab panels are slotted in.::part(body)
navThe tab group's navigation container where tabs are slotted in.::part(nav)
scroll-buttonThe previous/next scroll buttons that show when tabs are scrollable, a <cs-button>.::part(scroll-button)
scroll-button__buttonThe scroll button's exported button part.::part(scroll-button__button)
scroll-button-endThe ending scroll button.::part(scroll-button-end)
scroll-button-startThe starting scroll button.::part(scroll-button-start)
tab-groupThe component's outer wrapper.::part(tab-group)
tabsThe container that wraps the tabs.::part(tabs)

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.

SSR

Learn more about Server-Side Rendering (SSR).

During SSR, <cs-tab-group> can't access its children to determine which tab is active. To render the correct panel, manually set the active attribute on the matching <cs-tab> and <cs-tab-panel>.