Tabs

Switch between panels, or between routes.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrTab, WrTabs } from 'ngwr/tabs';

@Component({ imports: [WrTab, WrTabs] })
export class MyComponent {}

Content tabs

Bind [(active)] to a tab key.

Overview content — short and friendly.

<wr-tabs [(active)]="key">
  <wr-tab key="overview" title="Overview">Overview content…</wr-tab>
  <wr-tab key="details"  title="Details">Details content…</wr-tab>
  <wr-tab key="logs"     title="Logs">Logs content…</wr-tab>
</wr-tabs>

Router tabs

Give tabs a routerLink and add wrTabsRouting from ngwr/tabs/router, or the strip throws. Put a <router-outlet> below.

<!-- imports: [WrTabs, WrTab, WrTabsRouting] from 'ngwr/tabs' + 'ngwr/tabs/router' -->
<wr-tabs wrTabsRouting>
  <wr-tab title="Overview" routerLink="overview" />
  <wr-tab title="Details"  routerLink="details" />
  <wr-tab title="Logs"     routerLink="logs" />
</wr-tabs>
<router-outlet />

Disabled tab

Active
<wr-tab title="WIP" disabled>…</wr-tab>

Router adapter — template reference

#routing="wrTabsRouting" gives the template the adapter, for example href().

<wr-tabs wrTabsRouting #routing="wrTabsRouting">
  <wr-tab title="Overview" routerLink="overview" />
  <wr-tab title="Details" routerLink="details" />
</wr-tabs>

<!-- Anywhere else in the same template -->
<a [href]="routing.href('overview')">Permalink to the first tab</a>

Tabs API

NameDescriptionTypeDefault
activeActive tab key. Two-way bindable.string | nullnull
sizeVisual size variant.'sm' | 'md' | 'lg''md'

Tab API

NameDescriptionTypeDefault
titlerequiredVisible label.string—
keyStable id.stringauto
routerLinkMakes the tab a link; the strip renders no panel.string | readonly string[] | nullnull
disabledDisable the tab.booleanfalse

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/tabs's own element.

VariableDefaultDeclared on
--wr-tabs-bordervar(--wr-border-base).wr-tabs
--wr-tabs-colorvar(--wr-color-on-surface-muted).wr-tabs
--wr-tabs-color-activevar(--wr-color-primary-ink).wr-tabs
--wr-tabs-color-hovervar(--wr-color-on-surface).wr-tabs
--wr-tabs-fade1.5rem.wr-tabs__strip
--wr-tabs-fade-axisto right.wr-tabs__strip +1 variant override
--wr-tabs-fade-end0px.wr-tabs__strip +1 variant override
--wr-tabs-fade-start0px.wr-tabs__strip +1 variant override
--wr-tabs-font-familyvar(--wr-font-family-base).wr-tabs
--wr-tabs-font-sizevar(--wr-control-font-size-md).wr-tabs +2 variant overrides
--wr-tabs-font-weightvar(--wr-font-weight-medium).wr-tabs
--wr-tabs-indicatorvar(--wr-color-primary).wr-tabs
--wr-tabs-line-heightvar(--wr-control-line-height-md).wr-tabs +2 variant overrides
--wr-tabs-padding-xvar(--wr-space-lg).wr-tabs +2 variant overrides
--wr-tabs-padding-yvar(--wr-space-md).wr-tabs +2 variant overrides
--wr-tabs-panel-padding-topvar(--wr-space-lg).wr-tabs
--wr-tabs-strip-gapvar(--wr-space-xs).wr-tabs

Dependencies

Add-onngwr/tabs/router(needs @angular/router)

See also