Skip to main content

Overview

The Tab Bar component provides a tabbed navigation interface that allows users to switch between different content panels. Tabs help organize related content into separate views while keeping everything accessible from a single location.

Basic usage

Import the Tab Bar component and define your tabs:
import { TabBarComponent } from '@flowx/angular-ui-toolkit';

@Component({
  selector: 'app-example',
  standalone: true,
  imports: [TabBarComponent],
  template: `
    <flx-tab-bar
      [activeTab]="activeTabIndex"
      (tabChange)="onTabChange($event)">
      <flx-tab [label]="'Overview'">
        <p>Overview content</p>
      </flx-tab>
      <flx-tab [label]="'Details'">
        <p>Details content</p>
      </flx-tab>
      <flx-tab [label]="'Settings'">
        <p>Settings content</p>
      </flx-tab>
    </flx-tab-bar>
  `
})
export class ExampleComponent {
  activeTabIndex = 0;
  
  onTabChange(index: number) {
    this.activeTabIndex = index;
    console.log('Active tab:', index);
  }
}

Component selectors

<flx-tab-bar></flx-tab-bar>
<flx-tab></flx-tab>

Tab Bar properties

activeTab
number
default:"0"
Index of the currently active tab. Use two-way binding with [(activeTab)] for automatic state synchronization.
variant
'default' | 'pills' | 'underline'
default:"'default'"
Visual style of the tabs:
  • default: Standard tab appearance
  • pills: Rounded pill-shaped tabs
  • underline: Minimal tabs with bottom border indicator
alignment
'start' | 'center' | 'end' | 'stretch'
default:"'start'"
Horizontal alignment of tabs:
  • start: Tabs aligned to the left
  • center: Tabs centered
  • end: Tabs aligned to the right
  • stretch: Tabs fill available width equally
scrollable
boolean
default:"false"
When true, enables horizontal scrolling for tabs that don’t fit in the available width.
lazy
boolean
default:"false"
When true, tab content is only rendered when the tab becomes active for the first time.

Tab Bar events

tabChange
EventEmitter<number>
Emitted when the active tab changes. Returns the index of the newly activated tab.
activeTabChange
EventEmitter<number>
Emitted when the active tab index changes. Useful for two-way binding.

Tab properties

label
string
required
The text label displayed on the tab button.
icon
string
Icon name to display alongside or instead of the label.
disabled
boolean
default:"false"
When true, the tab cannot be selected and appears disabled.
badge
string | number
Badge content to display on the tab (e.g., notification count).
id
string
Unique identifier for the tab. If not provided, an auto-generated ID is used.

Content projection

Each <flx-tab> component uses content projection to display its panel content:
<flx-tab-bar>
  <flx-tab [label]="'Tab 1'">
    <!-- Content for Tab 1 -->
    <div class="tab-content">
      <h3>Tab 1 Content</h3>
      <p>This content is displayed when Tab 1 is active</p>
    </div>
  </flx-tab>
  <flx-tab [label]="'Tab 2'">
    <!-- Content for Tab 2 -->
    <div class="tab-content">
      <h3>Tab 2 Content</h3>
      <p>This content is displayed when Tab 2 is active</p>
    </div>
  </flx-tab>
</flx-tab-bar>

Examples

Simple tabbed interface with text content:
@Component({
  template: `
    <flx-tab-bar [(activeTab)]="selectedTab">
      <flx-tab [label]="'Profile'">
        <div class="profile-tab">
          <h3>User Profile</h3>
          <p>Name: {{ user.name }}</p>
          <p>Email: {{ user.email }}</p>
        </div>
      </flx-tab>
      
      <flx-tab [label]="'Preferences'">
        <div class="preferences-tab">
          <h3>User Preferences</h3>
          <label>
            <input type="checkbox" [(ngModel)]="preferences.notifications" />
            Enable notifications
          </label>
        </div>
      </flx-tab>
      
      <flx-tab [label]="'Security'">
        <div class="security-tab">
          <h3>Security Settings</h3>
          <button (click)="changePassword()">Change Password</button>
        </div>
      </flx-tab>
    </flx-tab-bar>
  `
})
export class UserSettingsComponent {
  selectedTab = 0;
  user = { name: 'John Doe', email: 'john@example.com' };
  preferences = { notifications: true };
  
  changePassword() {
    console.log('Change password');
  }
}
When using the lazy property, ensure that tab content components can handle being destroyed and recreated if users switch between tabs multiple times.

Accessibility

The Tab Bar component follows accessibility best practices:
  • Uses proper ARIA attributes (role="tablist", role="tab", role="tabpanel")
  • Supports keyboard navigation:
    • Arrow keys to move between tabs
    • Home/End keys to jump to first/last tab
    • Tab key to enter tab panel content
  • Announces active tab and panel content to screen readers
  • Manages focus appropriately when switching tabs
Avoid using too many tabs (more than 7-8) as this can overwhelm users. Consider using a dropdown menu or different navigation pattern for large numbers of options.

Styling

Customize tab bar appearance using CSS custom properties:
flx-tab-bar {
  --tab-bar-background: transparent;
  --tab-bar-border-color: #e0e0e0;
  --tab-color: #666666;
  --tab-active-color: #1976d2;
  --tab-hover-background: #f5f5f5;
  --tab-active-background: #e3f2fd;
  --tab-indicator-color: #1976d2;
  --tab-indicator-height: 2px;
  --tab-padding: 12px 24px;
  --tab-border-radius: 4px;
}

Common use cases

  • Settings panels: Organize settings into logical categories
  • Product details: Show different aspects of a product (overview, specs, reviews)
  • Dashboard views: Switch between different data visualizations
  • Multi-step forms: Guide users through form completion
  • Documentation: Organize code examples or different documentation sections
  • Content categories: Browse content organized by category
  • User profiles: Display different sections of user information

Build docs developers (and LLMs) love