# Tab Bar

Controlled application navigation with press-and-slide selection, an iOS-style search button and optional glass material.

Page: https://sui.draco.dev/docs/components/tab-bar

TabBar presents the primary destinations of an application, as on iOS. It controls nothing but the selection: routing and content stay with the application.

### Example: tab-bar-demo

```tsx
"use client";
import { TabBar } from "@workspace/ui/components/tab-bar";
import { useState } from "react";
import { TabBarStage, tabBarItems } from "../support/tab-bar-stage";
import type { ExampleProps } from "../types";

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  const items = tabBarItems(chinese);
  const [value, setValue] = useState("home");
  const [query, setQuery] = useState("");
  const current = items.find((item) => item.value === value)?.label;
  return (
    <TabBarStage status={query ? `${current} · ${query}` : current}>
      <TabBar
        glass
        aria-label={chinese ? "应用导航" : "Application navigation"}
        items={items}
        value={value}
        onValueChange={setValue}
        search={{
          label: chinese ? "搜索" : "Search",
          value: query,
          onValueChange: setQuery,
        }}
      />
    </TabBarStage>
  );
}
```

## Installation

```bash
npx shadcn@latest add @sui/tab-bar
```

With pnpm, Yarn or Bun, use `pnpm dlx`, `yarn dlx` or `bunx --bun` in place of `npx`, and `pnpm add`, `yarn add` or `bun add` in place of `npm install`.

Install with the shadcn CLI or use the shared `@workspace/ui` package. Follow the [installation guide](/docs/installation) to configure the registry, load styles, and choose import aliases.

## Usage

```tsx
import { TabBar } from "@workspace/ui/components/tab-bar";
import { HomeIcon, SettingsIcon } from "lucide-react";
import { useState } from "react";

export function ApplicationNavigation() {
  const [value, setValue] = useState("home");
  return (
    <TabBar
      aria-label="Application navigation"
      value={value}
      onValueChange={setValue}
      items={[
        { value: "home", label: "Home", icon: <HomeIcon /> },
        { value: "settings", label: "Settings", icon: <SettingsIcon /> },
      ]}
      search={{ onSubmit: (query) => console.log(query) }}
    />
  );
}
```

`value` names the current destination and `onValueChange` asks the application to select another, so it can update a router or show its own view. Item values must be unique. TabBar renders a navigation landmark of buttons and marks the current one with `aria-current`; it does not render panels. Use [Tabs](/docs/components/tabs) to switch panels within a page.

## In an app

A phone-sized screen: the bar switches the page content, and the search field filters every entry as you type. Search is controlled here, so the page shows results while it is open.

### Example: tab-bar-app

```tsx
"use client";
import { TabBar } from "@workspace/ui/components/tab-bar";
import { useState } from "react";
import { tabBarItems } from "../support/tab-bar-stage";
import type { ExampleProps } from "../types";

const entries = {
  en: {
    home: ["Morning brief", "Team standup notes", "Quarterly roadmap"],
    saved: ["Design tokens", "Glass guidelines", "Motion checklist"],
    activity: ["Ana commented", "Build passed", "Release v4.0.0"],
    settings: ["Appearance", "Notifications", "Privacy"],
  },
  zh: {
    home: ["今日简报", "站会记录", "季度路线图"],
    saved: ["设计令牌", "玻璃规范", "动效清单"],
    activity: ["Ana 发表了评论", "构建通过", "发布 v4.0.0"],
    settings: ["外观", "通知", "隐私"],
  },
};

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  const items = tabBarItems(chinese);
  const content = chinese ? entries.zh : entries.en;
  const [value, setValue] = useState<keyof typeof content>("home");
  const [open, setOpen] = useState(false);
  const [query, setQuery] = useState("");
  const all = Object.values(content).flat();
  const results = all.filter((entry) =>
    entry.toLowerCase().includes(query.trim().toLowerCase()),
  );
  const rows = open ? results : content[value];
  const searchLabel = chinese ? "搜索" : "Search";
  const heading = open
    ? searchLabel
    : items.find((item) => item.value === value)?.label;
  return (
    <div className="relative mx-auto flex h-[30rem] w-full max-w-md flex-col overflow-hidden rounded-[2.5rem] border bg-background">
      <div className="h-36 shrink-0 bg-linear-to-br from-sky-400/70 via-violet-400/60 to-rose-400/60" />
      <div className="-mt-10 flex min-h-0 flex-1 flex-col gap-3 overflow-auto px-5 pb-28">
        <h3 className="font-semibold text-2xl">{heading}</h3>
        <ul className="grid gap-2">
          {rows.map((entry) => (
            <li key={entry} className="rounded-2xl bg-muted px-4 py-3 text-sm">
              {entry}
            </li>
          ))}
        </ul>
        {rows.length ? null : (
          <p className="text-muted-foreground text-sm">
            {chinese ? "没有结果" : "No results"}
          </p>
        )}
      </div>
      <div className="absolute inset-x-4 bottom-4 flex justify-center">
        <TabBar
          glass
          size="sm"
          aria-label={chinese ? "应用导航" : "Application navigation"}
          items={items}
          value={value}
          onValueChange={(next) => setValue(next as keyof typeof content)}
          search={{
            label: searchLabel,
            open,
            onOpenChange: setOpen,
            value: query,
            onValueChange: setQuery,
          }}
        />
      </div>
    </div>
  );
}
```

## Material

The default bar uses the theme's muted surface. `glass` (optionally with settings, `glass={{ … }}`) or `frosted` applies [Glass](/docs/components/glass) to the bar and its search button. Both keep a neutral selection pill, as on iOS, with the icon and label in the contrast-adjusted theme foreground. Keep the surrounding container plain to avoid nesting glass.

### Example: tab-bar-material

```tsx
"use client";
import { TabBar } from "@workspace/ui/components/tab-bar";
import { useState } from "react";
import { TabBarStage, tabBarItems } from "../support/tab-bar-stage";
import type { ExampleProps } from "../types";

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  const items = tabBarItems(chinese);
  const [value, setValue] = useState("home");
  const modes = [
    { key: "default", label: chinese ? "默认" : "Default", props: {} },
    { key: "glass", label: chinese ? "玻璃" : "Glass", props: { glass: true } },
    {
      key: "frosted",
      label: chinese ? "磨砂" : "Frosted",
      props: { frosted: true },
    },
  ];
  return (
    <TabBarStage>
      {modes.map((mode) => (
        <div key={mode.key} className="grid justify-items-center gap-2">
          <p className="text-sm">{mode.label}</p>
          <TabBar
            {...mode.props}
            aria-label={mode.label}
            items={items}
            value={value}
            onValueChange={setValue}
            search={{ label: chinese ? "搜索" : "Search" }}
          />
        </div>
      ))}
    </TabBarStage>
  );
}
```

## Search

`search` adds a separate round button on the trailing side, as in iOS 26 and later. Pressing it hides the bar and reveals a field, as wide as the bar and button were, growing from the button toward the leading side. The close button or Escape folds the field back into the button before the bar returns; Enter calls `onSubmit`.

### Example: tab-bar-search

```tsx
"use client";
import { TabBar } from "@workspace/ui/components/tab-bar";
import { useState } from "react";
import { TabBarStage, tabBarItems } from "../support/tab-bar-stage";
import type { ExampleProps } from "../types";

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  const [value, setValue] = useState("home");
  const [submitted, setSubmitted] = useState("");
  const prefix = chinese ? "已搜索：" : "Searched: ";
  const hint = chinese
    ? "点按搜索按钮，输入后按 Enter"
    : "Press the search button, type and press Enter";
  return (
    <TabBarStage status={submitted ? `${prefix}${submitted}` : hint}>
      <TabBar
        frosted
        aria-label={chinese ? "应用导航" : "Application navigation"}
        items={tabBarItems(chinese)}
        value={value}
        onValueChange={setValue}
        search={{
          label: chinese ? "搜索" : "Search",
          placeholder: chinese ? "搜索收藏与动态" : "Search saved and activity",
          onSubmit: setSubmitted,
        }}
      />
    </TabBarStage>
  );
}
```

The field is uncontrolled by default (`defaultOpen`, `defaultValue`); pass `open`/`onOpenChange` or `value`/`onValueChange` to control it. `placeholder`, `label`, `closeLabel` and `icon` customize it. Closing from the field returns focus to the search button, and an open field keeps the bar's width as the viewport changes.

### Button only

With `mode: "button"` the button never expands: handle `onActivate` yourself, for example to open a search sheet, a route or, as here, any other trailing action.

### Example: tab-bar-search-button

```tsx
"use client";
import { TabBar } from "@workspace/ui/components/tab-bar";
import { SparklesIcon } from "lucide-react";
import { useState } from "react";
import { TabBarStage, tabBarItems } from "../support/tab-bar-stage";
import type { ExampleProps } from "../types";

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  const [value, setValue] = useState("home");
  const [count, setCount] = useState(0);
  return (
    <TabBarStage
      status={
        chinese
          ? `助手按钮已点按 ${count} 次`
          : `Assistant button pressed ${count} times`
      }
    >
      <TabBar
        glass
        aria-label={chinese ? "应用导航" : "Application navigation"}
        items={tabBarItems(chinese)}
        value={value}
        onValueChange={setValue}
        search={{
          mode: "button",
          label: chinese ? "助手" : "Assistant",
          icon: <SparklesIcon />,
          onActivate: () => setCount((previous) => previous + 1),
        }}
      />
    </TabBarStage>
  );
}
```

### Custom content

`render` replaces the field with your own content. It receives `close`, which plays the closing animation.

### Example: tab-bar-search-custom

```tsx
"use client";
import { Button } from "@workspace/ui/components/button";
import { TabBar } from "@workspace/ui/components/tab-bar";
import { useState } from "react";
import { TabBarStage, tabBarItems } from "../support/tab-bar-stage";
import type { ExampleProps } from "../types";

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  const [value, setValue] = useState("home");
  const [filter, setFilter] = useState<string | null>(null);
  const filters = chinese ? ["今天", "本周", "全部"] : ["Today", "Week", "All"];
  const prefix = chinese ? "筛选：" : "Filter: ";
  const hint = chinese ? "展开后显示自定义内容" : "Opens into custom content";
  return (
    <TabBarStage status={filter ? `${prefix}${filter}` : hint}>
      <TabBar
        glass
        aria-label={chinese ? "应用导航" : "Application navigation"}
        items={tabBarItems(chinese)}
        value={value}
        onValueChange={setValue}
        search={{
          label: chinese ? "筛选" : "Filter",
          render: ({ close }) => (
            <div className="flex flex-1 items-center justify-between gap-1 px-1">
              {filters.map((option) => (
                <Button
                  key={option}
                  variant="ghost"
                  className="flex-1 rounded-full"
                  onClick={() => {
                    setFilter(option);
                    close();
                  }}
                >
                  {option}
                </Button>
              ))}
            </div>
          ),
        }}
      />
    </TabBarStage>
  );
}
```

## Sizes

`size` is `"sm"`, `"default"` or `"lg"`; the search button follows it.

### Example: tab-bar-sizes

```tsx
"use client";
import { TabBar } from "@workspace/ui/components/tab-bar";
import { useState } from "react";
import { TabBarStage, tabBarItems } from "../support/tab-bar-stage";
import type { ExampleProps } from "../types";

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  const items = tabBarItems(chinese).slice(0, 3);
  const [value, setValue] = useState("home");
  return (
    <TabBarStage>
      {(["sm", "default", "lg"] as const).map((size) => (
        <TabBar
          key={size}
          size={size}
          glass
          aria-label={size}
          items={items}
          value={value}
          onValueChange={setValue}
          search={{ label: chinese ? "搜索" : "Search" }}
        />
      ))}
    </TabBarStage>
  );
}
```

## Labels only and disabled

Icons are optional. A disabled item cannot be selected, held or focused with the arrow keys.

### Example: tab-bar-labels

```tsx
"use client";
import { TabBar } from "@workspace/ui/components/tab-bar";
import { useState } from "react";
import { TabBarStage } from "../support/tab-bar-stage";
import type { ExampleProps } from "../types";

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  const [value, setValue] = useState("all");
  return (
    <TabBarStage>
      <TabBar
        aria-label={chinese ? "收件箱筛选" : "Inbox filters"}
        size="sm"
        items={[
          { value: "all", label: chinese ? "全部" : "All" },
          { value: "unread", label: chinese ? "未读" : "Unread" },
          { value: "flagged", label: chinese ? "已标记" : "Flagged" },
          {
            value: "archived",
            label: chinese ? "已归档" : "Archived",
            disabled: true,
          },
        ]}
        value={value}
        onValueChange={setValue}
      />
    </TabBarStage>
  );
}
```

## RTL

Horizontal bars follow the document direction: arrow keys, the press-and-slide lens and the search reveal all mirror.

### Example: tab-bar-rtl

```tsx
"use client";
import { TabBar } from "@workspace/ui/components/tab-bar";
import { BellIcon, HomeIcon, SettingsIcon } from "lucide-react";
import { useState } from "react";
import { TabBarStage } from "../support/tab-bar-stage";

export default function Example() {
  const [value, setValue] = useState("home");
  return (
    <TabBarStage>
      <TabBar
        dir="rtl"
        glass
        aria-label="التنقل"
        items={[
          { value: "home", label: "الرئيسية", icon: <HomeIcon /> },
          { value: "activity", label: "النشاط", icon: <BellIcon /> },
          { value: "settings", label: "الإعدادات", icon: <SettingsIcon /> },
        ]}
        value={value}
        onValueChange={setValue}
        search={{ label: "بحث" }}
      />
    </TabBarStage>
  );
}
```

## Keyboard

Left and Right arrows move among enabled destinations; Home and End focus the first and last. Moving focus does not change the destination; Enter or Space activates the focused one. Only the current destination is in the Tab sequence. The bar scrolls when destinations exceed its space.

## Press and slide

Hold an item for 250ms, or drag beyond 6px, to lift the selection into a floating lens that enlarges the icon and label. Slide to move the lens over other items; releasing selects the item under it. Past either end the lens follows with growing resistance and keeps the end item. Releasing well away from the bar, cancelling the pointer or losing window focus restores the original selection. In glass mode the lens is clear, with edge highlights and a floating shadow but no blur or refraction, and the bar's glass stays still underneath.

## Motion

GSAP moves the selection pill and lens using the buttons' measured bounds. The search field takes its final width at once and a rounded clip reveals it, so glass measures it a single time rather than following a resize; closing plays the clip in reverse, then fades the bar in. Reduced-motion preferences turn off all of these animations.

## API reference

| Prop | Type | Default / behavior |
| --- | --- | --- |
| `items` | `readonly TabBarItem[]` | Destinations: `value`, `label`, optional `icon` and `disabled`. |
| `value` | `string` | Controlled current destination. |
| `onValueChange` | `(value: string) => void` | Called when selecting an enabled destination. |
| `onItemActivate` | `(value: string) => void` | Called on every activation, including the current item. |
| `search` | `TabBarSearch` | Optional trailing search button; see below. |
| `glass`, `frosted` | `boolean \| GlassConfig`, `boolean` | `false`; material for the bar and search button. |
| `size` | `"sm" \| "default" \| "lg"` | `"default"`. |
| `feedback` | `FeedbackOption` | Follows `FeedbackProvider`; haptics on selection and long press. |
| Other props | Native nav props | Includes `aria-label`, `dir`, `className`, `style` and `ref`. |

### TabBarSearch

| Field | Type | Default / behavior |
| --- | --- | --- |
| `mode` | `"expand" \| "button"` | `"expand"`. |
| `label` | `string` | `"Search"`; accessible name and placeholder fallback. |
| `icon` | `ReactNode` | A search icon. |
| `onActivate` | `() => void` | Called when the button is pressed or the field opens. |
| `open`, `defaultOpen`, `onOpenChange` | `boolean`, `boolean`, `(open: boolean) => void` | Whether the field is shown. |
| `value`, `defaultValue`, `onValueChange` | `string`, `string`, `(value: string) => void` | The query. |
| `onSubmit` | `(value: string) => void` | Called on Enter. |
| `placeholder` | `string` | Defaults to `label`. |
| `closeLabel` | `string` | `"Close search"`; the close button's accessible name. |
| `render` | `({ open, close }) => ReactNode` | Replaces the field. |
