Tabs
The <smart-tabs> component renders a tabbed navigation strip (anchor-based for routing or button-based for in-page selection) with a <select> fallback for mobile. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract TabsBaseComponent defines the shared API — options (ITabsOptions), selectedId (two-way ModelSignal<string | null>), cssClass (alias class), and the tabChange output. TabsStandardComponent is a barebones placeholder using native <nav>, <ul>, <a>, <button> and <select> elements. TabsComponent is the public wrapper that renders TabsStandardComponent by default and accepts a custom replacement via TABS_STANDARD_COMPONENT_TOKEN.
Usage
<smart-tabs
[options]="options"
[(selectedId)]="selectedTab"
(tabChange)="onTabChange($event)"
/>
@if (lastTab()) {
<p>Last chosen tab: {{ lastTab() }}</p>
}
The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Components
TabsComponent (<smart-tabs>)
Main wrapper. Delegates to TabsStandardComponent by default. When TABS_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet and hands it options, selectedId and class. Re-emits tabChange and forwards two-way selectedId of whichever implementation renders (the standard, the preset or a custom one).
TabsStandardComponent (<smart-tabs-standard>)
Barebones placeholder using native HTML. Renders an outer wrapper with cssClass, an optional mobile <select> in .tabs-mobile (rendered when options.showMobileSelect is true or unset and items is non-empty; aria-label from options.ariaLabel, default "Select a tab"; one option per item with its label, or its id without one; a change emits tabChange and updates selectedId), and a <nav class="tabs-desktop"> (aria-label from options.ariaLabel, default "Tabs") containing a <ul class="tabs-list"> of items. Each item renders as a plain <a class="tab-link" href> when href is provided (a click follows the link without changing the selection), otherwise <button class="tab-button"> emitting tabChange and updating selectedId. Adds the current class and aria-current="page" when item.id === selectedId() (no item is current while selectedId is null). Supports optional iconTpl and badge per item. The standard does not read options.layout and adds no styles: the class hooks are for your CSS.
TabsPresetComponent (<smart-tabs-preset>)
Styled variation that extends TabsBaseComponent and is a drop-in replacement for TabsStandardComponent. Register it via TABS_STANDARD_COMPONENT_TOKEN (or every preset at once with provideSmartPresets()) to restyle every <smart-tabs>, or use the <smart-tabs-preset> selector directly. It renders the translated Preline tab nav for every SmartTabsLayout (underline, underline-with-icons, underline-with-badges, underline-full-width, pills, pills-on-gray, pills-with-brand-color, bar-with-underline, simple), selected through options.layout (default 'underline'). Honors options.items (rendering <a role="tab"> when href is set, otherwise <button role="tab">), options.ariaLabel, per-item iconTpl and badge, and options.showMobileSelect (default true → renders a <select> shown only below sm and hides the nav below sm). The active tab is driven by the selectedId model (falling back to the first item); a click on a tab — a link included — or a change of the mobile select sets selectedId and emits tabChange. Preline's Tabs JS plugin is not used. ARIA (role=tablist/tab, aria-selected, aria-controls, aria-orientation) is kept on the markup. All classes are smart:-prefixed Tailwind with explicit dark: variants; the per-layout class recipes are internal to the preset and not exported.
TabsPresetComponentdeclarescssClassasinput<string>('')without theclassalias. Bind it as[cssClass]when using the<smart-tabs-preset>selector directly, or just passclasson<smart-tabs>(the wrapper forwards it). With the preset registered through the token,(tabChange)and[(selectedId)]on<smart-tabs>work as with the standard.
TabsBaseComponent (abstract)
Abstract base directive. Exposes:
options: InputSignal<ITabsOptions | undefined>selectedId: ModelSignal<string | null>(defaultnull)cssClass: InputSignal<string>(aliasclass)tabChange: OutputEmitterRef<ITabChange>
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
options | InputSignal<ITabsOptions | undefined> | - | Tabs configuration |
selectedId | ModelSignal<string | null> | null | Two-way bindable currently selected tab id |
class | InputSignal<string> | '' | External CSS classes (alias for cssClass) |
Outputs
| Output | Type | Description |
|---|---|---|
tabChange | OutputEmitterRef<ITabChange> | Emitted when a tab is chosen: a button click or a mobile select change (and, in the preset, a link click too). |
ITabsOptions
| Field | Type | Default | Description |
|---|---|---|---|
items | ITabItem[] | [] | The tabs. |
ariaLabel | string | 'Tabs' | Accessible name of the strip; the standard mobile select uses it too, with 'Select a tab' as its own default. |
showMobileSelect | boolean | true | Renders a <select> of the tabs; the preset shows it below sm and the strip from sm up. |
layout | SmartTabsLayout | 'underline' | Preset only: the look (see the preset section). The standard ignores it. |
SmartTabsLayout is 'underline' | 'underline-with-icons' | 'underline-with-badges' | 'underline-full-width' | 'pills' | 'pills-on-gray' | 'pills-with-brand-color' | 'bar-with-underline' | 'simple'.
ITabItem
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Identifies the tab (selectedId, tabId, and the preset's aria-controls; give your panel that id). |
label | string | - | Tab text (the mobile select falls back to the id). |
href | string | - | Renders the tab as a plain <a href>; the standard follows the link without changing the selection. |
badge | string | number | - | A count or text badge. |
iconTpl | TemplateRef<unknown> | - | Icon before the label. |
ITabChange
| Field | Type | Default | Description |
|---|---|---|---|
tabId | string | required | The id of the chosen tab. |
TABS_STANDARD_COMPONENT_TOKEN
Provide a component class extending TabsBaseComponent under TABS_STANDARD_COMPONENT_TOKEN; every <smart-tabs> below that injector renders it.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
computed,
signal,
ViewEncapsulation,
} from '@angular/core';
import {
ITabsOptions,
TABS_STANDARD_COMPONENT_TOKEN,
TabsBaseComponent,
TabsComponent,
} from '@smartsoft001/angular';
@Component({
selector: 'docs-custom-tabs',
template: `
<nav
[class]="containerClasses()"
[attr.aria-label]="options()?.ariaLabel ?? 'Tabs'"
>
@for (item of options()?.items ?? []; track item.id) {
<button
type="button"
[class]="tabClasses(item.id)"
[attr.aria-current]="isCurrent(item.id) ? 'page' : null"
(click)="select(item.id)"
>
{{ item.label ?? item.id }}
@if (item.badge !== undefined && item.badge !== null) {
<span class="docs-tabs__badge">{{ item.badge }}</span>
}
</button>
}
</nav>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomTabsComponent extends TabsBaseComponent {
containerClasses = computed(() =>
['docs-tabs', this.cssClass()].filter(Boolean).join(' '),
);
// selectedId is a model on the base: the implementation updates it and
// announces the change through the tabChange output.
select(tabId: string): void {
this.selectedId.set(tabId);
this.tabChange.emit({ tabId });
}
protected isCurrent(tabId: string): boolean {
return this.selectedId() === tabId;
}
protected tabClasses(tabId: string): string {
return this.isCurrent(tabId)
? 'docs-tabs__tab docs-tabs__tab--current'
: 'docs-tabs__tab';
}
}
@Component({
selector: 'docs-tabs-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [TabsComponent],
// The token swaps the standard tabs for the custom one everywhere below this
// component, so consumers keep writing `<smart-tabs>`.
providers: [
{
provide: TABS_STANDARD_COMPONENT_TOKEN,
useValue: CustomTabsComponent,
},
],
// The wrapper forwards `selectedId` both ways and re-emits `tabChange` of
// the custom component.
template: `
<smart-tabs
[options]="options"
[(selectedId)]="selectedId"
(tabChange)="lastTab.set($event.tabId)"
/>
@if (lastTab()) {
<p>Last chosen tab: {{ lastTab() }}</p>
}
`,
})
export class TabsCustomExampleComponent {
readonly selectedId = signal<string | null>('billing');
readonly lastTab = signal<string | null>(null);
options: ITabsOptions = {
ariaLabel: 'Account sections',
items: [
{ id: 'account', label: 'Account' },
{ id: 'billing', label: 'Billing' },
{ id: 'members', label: 'Members', badge: 12 },
],
};
}
Source
The component lives in packages/shared/angular/src/lib/components/tabs and is documented for Claude Code by the angular-components-tabs skill.
SmartTabs renders the tab strip only; the parent renders the content of the selected tab. Tabs are buttons that select themselves, or links (href, rendered through the navigation adapter's linkComponent for internal paths). The selection is controlled (selectedId + onSelectedIdChange) or kept inside (defaultSelectedId); onTabChange({ tabId }) reports every choice. Unless options.showMobileSelect is false, a <select> of the tabs is rendered too: the preset shows it below sm and the strip from sm up, the standard rendering marks the two with the tabs-mobile / tabs-desktop class hooks for your CSS. SmartTabsPreset renders the nine layouts with role="tablist" / tab, aria-selected and aria-controls={item.id} (give your panel that id).
Usage
import { useState } from 'react';
import { ITabChange, ITabsOptions, SmartTabs } from '@smartsoft001/react';
const options: ITabsOptions = {
ariaLabel: 'Account settings',
items: [
{ id: 'account', label: 'My account' },
{ id: 'company', label: 'Company' },
{ id: 'team', label: 'Team members', badge: 4 },
{ id: 'billing', label: 'Billing' },
],
};
export function TabsUsageExample() {
const [selectedTab, setSelectedTab] = useState<string | null>('account');
const [lastTab, setLastTab] = useState<string | null>(null);
const onTabChange = ({ tabId }: ITabChange) => setLastTab(tabId);
return (
<>
<SmartTabs
options={options}
selectedId={selectedTab}
onSelectedIdChange={setSelectedTab}
onTabChange={onTabChange}
/>
{lastTab && <p>Last chosen tab: {lastTab}</p>}
</>
);
}
The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Exports
All from @smartsoft001/react.
| Export | Kind | What it is |
|---|---|---|
SmartTabs | component | Renders the implementation registered as components.tabs on SmartProvider, SmartTabsStandard by default. |
SmartTabsPreset | component | Styled tabs variation (preset). |
SmartTabsStandard | component | The default tabs rendering. |
useTabs | hook | The behaviour every tabs variant shares: the selection, controlled through selectedId or kept internally when that prop is undefined, and selectTab, which selects a tab and reports it through onSelectedIdChange and onTabChange. |
The preset's class helpers (getTabsContainerClasses, getTabsNavClasses, getTabsTriggerClasses, getTabsBadgeClasses, getTabsIconClasses, getTabsMobileSelectClasses) are exported too, with the type SmartTabsPresetLayout (the layout argument of the helpers), for a custom implementation that wants the preset look.
Props and Types
SmartTabsProps
| Prop | Type | Default | Description |
|---|---|---|---|
options? | ITabsOptions | — | Items, layout, accessible name and the mobile select. |
selectedId? | string | null | — | The id of the selected tab (null for none). Leave it undefined to let the component keep the selection. |
defaultSelectedId? | string | null | null | The initial selection of an uncontrolled component. |
onSelectedIdChange? | (selectedId: string) => void | — | Called with the id of the selected tab. |
onTabChange? | (event: ITabChange) => void | — | A tab was chosen (button click, preset link click or mobile select). |
className? | string | — | Classes on the root element. |
ITabsOptions
| Field | Type | Default | Description |
|---|---|---|---|
layout? | SmartTabsLayout | 'underline' | Preset look; the standard rendering ignores it. |
items? | ITabItem[] | [] | The tabs. |
ariaLabel? | string | 'Tabs' | Accessible name of the strip; the standard mobile select uses it too, with 'Select a tab' as its own default. |
showMobileSelect? | boolean | true | Renders a <select> of the tabs for small screens. |
ITabChange
| Field | Type | Default | Description |
|---|---|---|---|
tabId | string | required | The id of the chosen tab. |
ITabItem
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Identifies the tab (selectedId, tabId, and the preset's aria-controls). |
label? | string | — | Tab text. |
href? | string | — | Renders the tab as a link; the standard rendering follows the link without changing the selection. |
badge? | string | number | — | A count or text badge. |
iconTpl? | ReactNode | — | Icon before the label. |
Related types
SmartTabsLayout:'underline' \| 'underline-with-icons' \| 'underline-with-badges' \| 'underline-full-width' \| 'pills' \| 'pills-on-gray' \| 'pills-with-brand-color' \| 'bar-with-underline' \| 'simple'
Replacing the Implementation
SmartTabs renders the component registered under the 'tabs' key of SmartProvider's components, and SmartTabsStandard when nothing is registered there. Every SmartTabs below the provider then renders the registered component, which receives the same props.
SmartTabsPreset is the styled (preset) implementation: register it under the 'tabs' key of SmartProvider's components, render it directly in place of SmartTabs, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.
The useTabs hook
The behaviour every tabs variant shares: the selection, controlled through selectedId or kept internally when that prop is undefined, and selectTab, which selects a tab and reports it through onSelectedIdChange and onTabChange.
| Returns | Type | Description |
|---|---|---|
selectedId | string | null | The selected id (controlled or internal). |
selectTab | (tabId: string) => void | Selects a tab and reports onSelectedIdChange and onTabChange. |
import { useState } from 'react';
import {
ITabsOptions,
SmartProvider,
SmartTabs,
SmartTabsProps,
useTabs,
} from '@smartsoft001/react';
export function CustomTabs(props: SmartTabsProps) {
const { options, className } = props;
// useTabs keeps the selection (controlled or internal) and reports a choice
// through onSelectedIdChange and onTabChange.
const { selectedId, selectTab } = useTabs(props);
return (
<nav
className={['docs-tabs', className].filter(Boolean).join(' ')}
aria-label={options?.ariaLabel ?? 'Tabs'}
>
{(options?.items ?? []).map((item) => {
const current = item.id === selectedId;
return (
<button
key={item.id}
type="button"
className={
current
? 'docs-tabs__tab docs-tabs__tab--current'
: 'docs-tabs__tab'
}
aria-current={current ? 'page' : undefined}
onClick={() => selectTab(item.id)}
>
{item.label ?? item.id}
{item.badge !== undefined && item.badge !== null && (
<span className="docs-tabs__badge">{item.badge}</span>
)}
</button>
);
})}
</nav>
);
}
// A module constant: a new object on every render would change the context.
const components = { tabs: CustomTabs };
const options: ITabsOptions = {
ariaLabel: 'Account sections',
items: [
{ id: 'account', label: 'Account' },
{ id: 'billing', label: 'Billing' },
{ id: 'members', label: 'Members', badge: 12 },
],
};
// Every <SmartTabs> below the provider renders CustomTabs. Without selectedId
// the selection lives in the implementation and starts at defaultSelectedId.
export function TabsCustomExample() {
const [lastTab, setLastTab] = useState<string | null>(null);
return (
<SmartProvider components={components}>
<SmartTabs
options={options}
defaultSelectedId="billing"
onTabChange={({ tabId }) => setLastTab(tabId)}
/>
{lastTab && <p>Last chosen tab: {lastTab}</p>}
</SmartProvider>
);
}
Styling
- The standard rendering is unstyled; the preset treats the first item as current when nothing is selected and carries
smart:dark:variants.
Source
The component lives in packages/shared/react/src/lib/components/tabs and is documented for Claude Code by the react-components-tabs skill.