Tabs
Import
Import TableauUiTabgroupModule from tableau-ui-angular/tab-group.
A tab group
A tab-group holds tab elements. In each, the element marked tab-header is its header, and the rest is its content. The group starts on the first enabled tab. It is one Tab stop, the selected tab, and the arrow keys move between the tabs and select them. Every tab's content stays in the page, hidden while another tab is selected.
| Input or output | What it does |
|---|---|
[disabled], on a tab | Keeps the tab from being selected; the arrow keys pass it |
key, on a tab | A name for selectTabByKey() |
(afterActivate), on a tab | Emitted each time the tab is selected, once its content shows; in the browser only |
(tabSelected) | Emitted each time a tab is selected, with its index, its key and the tab |
label | Names the strip of tabs for screen readers |
[autoSelectFirstTab] | Starts on the first enabled tab; true by default |
selectTabByIndex() and selectTabByKey() select a tab from code, and $selectedIndex and $selectedTab give the selection as signals.
The second tab, the first one enabled, so the group shows it first.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { TableauUiTabgroupModule } from 'tableau-ui-angular/tab-group';
@Component({
selector: 'app-tabs-basic-example',
imports: [TableauUiTabgroupModule],
templateUrl: './tabs-basic.example.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TabsBasicExampleComponent {
// afterActivate runs once a tab's content shows, in the browser
protected readonly $activated = signal('none yet');
}The headers
headerPadding sets the headers' padding, 0.25rem 1.5rem by default. The header's own element takes any style, such as a larger font.
The second tab.
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { TableauUiTabgroupModule } from 'tableau-ui-angular/tab-group';
@Component({
selector: 'app-tabs-header-example',
imports: [TableauUiTabgroupModule],
templateUrl: './tabs-header.example.html',
styleUrl: './tabs-header.example.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TabsHeaderExampleComponent {}A narrow group
When the headers don't fit, arrows at each end of the strip scroll it, and selecting a tab scrolls its header into view. scrollArrowsIconSize sets the arrows' size, 1.5rem by default.
First tab.
First tab.
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { TableauUiTabgroupModule } from 'tableau-ui-angular/tab-group';
@Component({
selector: 'app-tabs-narrow-example',
imports: [TableauUiTabgroupModule],
templateUrl: './tabs-narrow.example.html',
styleUrl: './tabs-narrow.example.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TabsNarrowExampleComponent {
protected readonly tabs = ['First', 'Second', 'Third', 'Fourth', 'Fifth'];
}Accessibility
A tab group follows the WAI-ARIA tabs pattern, and selects a tab as the arrow keys move to it.
- The strip is a
tablist, named bylabel. Each header is atabthat says whether it is selected or disabled, and each tab's content is atabpanelnamed by its tab. - The group is one Tab stop: the selected tab, or the first enabled one while none is selected, with
[autoSelectFirstTab]="false". The next Tab goes to the selected tab's content, past the strip's scroll arrows when they show, then on through the page. - Each arrow key selects the tab it moves to, so
(tabSelected)and(afterActivate)run once for each. A tab that loads its data on them gets it once per key; wait for the user to stop, or load it once.
| Key, on a tab | What it does |
|---|---|
| Right, Left | Moves to the next or the previous enabled tab, past the end to the other end, and selects it |
| Home, End | Moves to the first or the last enabled tab, and selects it |
| Enter, Space | Selects the tab |