> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Tab Bar

Switch between your app's top-level screens from a row of icon-and-label tabs along the bottom of the screen, as most mobile apps do.


## Installation

```bash
npx @blotch/dolan add tab-bar
```

```typescript
import { UiTabBar, UiTabBarItem } from '../components/ui/tab-bar';
```

This also adds [Icon](/dolan/icon.md), whose icons and theme colors the tabs draw with.

## Usage

Give each tab a `route`, an `icon` and a `label`, and put the bar under a [`<lynx-tab-outlet>`](/guide/routing.md#keep-each-tab-alive-as-a-tab-bar-does), which keeps each tab as a native tab bar does:

```typescript title="src/app/app.ts"
import { Component } from '@angular/core';
import { LYNX_ELEMENTS, LynxTabOutlet } from '@blotch/angular-lynx';
import { UiTabBar, UiTabBarItem } from '../components/ui/tab-bar';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, LynxTabOutlet, UiTabBar, UiTabBarItem],
  template: `
    <view class="flex h-full flex-col bg-background">
      <lynx-tab-outlet />
      <ui-tab-bar>
        <ui-tab-bar-item route="/home" icon="home" label="Home" />
        <ui-tab-bar-item route="/search" icon="search" label="Search" />
        <ui-tab-bar-item route="/profile" icon="user" label="Profile" />
      </ui-tab-bar>
    </view>
  `,
})
export class App {}
```

- **A tap navigates** to the tab's `route`, with Angular's own [`RouterLink`](/guide/routing.md#navigate-between-screens). Set up the router with `provideRouter()` from `@blotch/angular-lynx`.
- **The tab of the current route is selected:** its icon and label take the theme's `primary` color, and the others its `muted-foreground`.
- **A tab stays selected on the routes under it.** The Inbox tab at `/inbox` is still selected at `/inbox/42`.
- **A tab shows selected as soon as it's tapped,** before the screen it shows has been built, so a tab that takes a moment to build doesn't look like a missed tap. If the navigation ends somewhere else (a guard says no or redirects, or it fails), the tab of the route the app is on is selected again.
- **Going back to a tab finds it as you left it,** with `<lynx-tab-outlet>`: its scroll positions, the screens pushed in it, and its native views. A tap on the selected tab pops its stack to its first screen. With `<router-outlet>`, each tab is built again every time.
- **The tabs share the bar's width equally,** and the bar pads itself by the bottom [safe area](/guide/safe-area.md), so the tabs sit above the iPhone's home indicator.
- **The icon is any [Icon](/dolan/icon.md) name,** or [your own mark](#your-own-mark).

Give each routed screen's host `flex-1` so it fills the space above the bar, or its `<scroll-view>` grows to fit its content instead of scrolling:

```typescript
@Component({
  selector: 'app-home',
  host: { class: 'flex flex-1 flex-col' },
  template: `
    <scroll-view scroll-orientation="vertical" class="h-full w-full">
      <text>Home</text>
    </scroll-view>
  `,
})
export class Home {}
```

### Away on a pushed screen

Give a tab a [`<lynx-stack-outlet>`](/guide/routing.md#the-tab-bar-or-dock-goes-away-on-a-pushed-screen), and a screen it pushes over the tab's first screen takes the bar away, as iOS's `hidesBottomBarWhenPushed` and Material's navigation bar do. The example's Inbox is one: open a message.

- **While it's away,** the bar lies over the bottom of the screen rather than under the outlet, so the pushed screen runs to the bottom edge.
- **Where screens move as iOS's do,** the screen underneath carries the bar: it moves a little left with that screen, and the pushed screen slides over it, rounded corner and shadow and all.
- **Where they move as Android's do,** it slides down off the screen.
- **Back, Android's back button or a swipe brings it back,** following the finger while it drags. While it's away, screen readers skip it and it takes no taps.

A route keeps the bar with `data: { bottomBar: 'visible' }`. See [`LynxStackChrome`](/api/angular-lynx/routing.md#lynxstackchrome) for what the stack says, and [`LynxStackBottomBar`](/api/angular-lynx/routing.md#lynxstackbottombar) for how a screen carries the bar.

### Badges

`[badge]` shows a count or a short text over the tab's icon, such as unread messages:

```angular-html
<ui-tab-bar-item
  route="/inbox"
  icon="inbox"
  label="Inbox"
  [badge]="unreadCount()"
/>
```

A count of `0`, an empty string, `null` or `undefined` shows no badge, so bind the count as it is.

### Your own mark

For a mark the icon set doesn't have, such as your app's logo on the Home tab, pass its markup to `svg` instead of `icon`:

```typescript
@Component({
  imports: [UiTabBar, UiTabBarItem],
  template: `
    <ui-tab-bar>
      <ui-tab-bar-item route="/home" [svg]="logo" label="Home" />
      <ui-tab-bar-item route="/search" icon="search" label="Search" />
    </ui-tab-bar>
  `,
})
export class App {
  // The app's logo (its path shortened here), filled with currentColor.
  readonly logo = `<svg viewBox="0 0 24 24"><path fill="currentColor" d="…"/></svg>`;
}
```

- **`currentColor` takes the tab's color,** as the set's icons do: `primary` while it's selected and `muted-foreground` otherwise. A one-color mark written in `currentColor` follows the selection and your theme.
- **Colors written out stay,** so a multi-color mark keeps them.
- **`xmlns` is optional,** and lines must be `<path>`s, as for [an icon's own SVG](/dolan/icon.md#your-own-svg).

### A tab for the root route

Every route starts with `/`, so a tab for `/` would stay selected everywhere. Match it exactly:

```angular-html
<ui-tab-bar-item
  route="/"
  icon="home"
  label="Home"
  [routerLinkActiveOptions]="{ exact: true }"
/>
```

### Router options

The item takes `RouterLink`'s inputs, which work as on the web: `queryParams`, `queryParamsHandling`, `fragment`, `preserveFragment`, `state`, `info`, `relativeTo`, `replaceUrl` and `skipLocationChange`.

```angular-html
<ui-tab-bar-item
  route="/profile"
  icon="user"
  label="Profile"
  [queryParams]="{ tab: 'posts' }"
  [replaceUrl]="true"
/>
```

- **Each tap adds a history entry,** as any `RouterLink` does, so Android's back button walks back through the tabs. Set `replaceUrl` to replace the entry instead.
- **A relative `route` resolves from the component the bar is in.** A bar inside a routed screen can switch its child routes with `route="feed"`.

### React to a tap

`(pressed)` emits on every tap, including one on the tab that's already selected, where the route doesn't change. Native apps scroll the screen back to the top then:

```angular-html
<ui-tab-bar-item
  route="/home"
  icon="home"
  label="Home"
  (pressed)="onHomeTap()"
/>
```

### Dark mode

The icons draw with the light theme's colors until you say otherwise, as every icon does. If your app switches to dark mode, set the icons' color scheme with [`provideIconTheme()`](/dolan/icon.md#dark-mode).

## API

### UiTabBar

| Input   | Type     | Default | Description                         |
| ------- | -------- | ------- | ----------------------------------- |
| `class` | `string` | `''`    | Extra Tailwind classes for the bar. |

### UiTabBarItem

| Input                     | Type                                                          | Default     | Description                                                                                                                              |
| ------------------------- | ------------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `route`                   | `string \| any[] \| UrlTree \| null`                          | —           | Where a tap navigates. `RouterLink`'s `routerLink`.                                                                                      |
| `icon`                    | `IconName \| undefined`                                       | `undefined` | The [Icon](/dolan/icon.md) drawn above the label. Give this or `svg`.                                                                    |
| `svg`                     | `string \| undefined`                                         | `undefined` | SVG markup to draw instead, such as your logo, with `currentColor` in the tab's color. Give this or `icon`.                              |
| `label`                   | `string`                                                      | —           | Required. The tab's name, shown and read by screen readers.                                                                              |
| `badge`                   | `string \| number \| null \| undefined`                       | `undefined` | A count or short text over the icon. Hidden for `0`, `''`, `null` and `undefined`.                                                       |
| `routerLinkActiveOptions` | `{ exact: boolean } \| IsActiveMatchOptions`                  | subset      | How the current route is matched. `RouterLinkActive`'s input.                                                                            |
| `queryParams`, …          | See [`RouterLink`](https://angular.dev/api/router/RouterLink) | —           | `queryParams`, `queryParamsHandling`, `fragment`, `preserveFragment`, `state`, `info`, `relativeTo`, `replaceUrl`, `skipLocationChange`. |
| `class`                   | `string`                                                      | `''`        | Extra Tailwind classes for the tab's content.                                                                                            |

| Output    | Type   | Description                                              |
| --------- | ------ | -------------------------------------------------------- |
| `pressed` | `void` | Emits on every tap, including a tap on the selected tab. |

## Accessibility

- **Each tab is one button,** named by its `label` and then its badge: "Inbox, 3".
- **The selected tab has the `selected` trait,** from the tap, as it shows, so iOS VoiceOver announces it as selected. Android has no selected trait, so TalkBack doesn't say which tab is selected.
- **On iOS, the bar has the `tabbar` trait,** as a native tab bar does, which tells VoiceOver that its buttons are tabs.
- **Away on a pushed screen,** the bar is hidden from screen readers and takes no taps.

## Related

- [Routing and navigation](/guide/routing.md): set up the router and its routes
- [Safe area](/guide/safe-area.md): the inset the bar pads for
- [Dock](/dolan/dock.md): the same navigation as a floating Liquid Glass bar
- [Tabs](/dolan/tabs.md): switch panels within one screen instead of routed screens
- [Nav Drawer](/dolan/nav-drawer.md): a side menu, for more destinations than a tab bar fits
- [Icon](/dolan/icon.md): the icons a tab can show, and how to write your own mark
