---
title: Tabs 标签页
description: 带分组、自定义 value 与默认索引的标签面板。
---

Tabs 由运行时在客户端切换面板，不刷新页面。标签列表为
`role="tablist"`，带正确的 `aria-selected` 状态。

## 纯标题

```ts
tabs({ items: ['预览', '代码', '说明'] });
```

## 带内容的面板

```ts
tabs({
  label: '包管理器',
  panels: [
    { title: 'bun', content: code('bun add @iconify-json/lucide') },
    { title: 'npm', content: code('npm install @iconify-json/lucide') },
    { title: 'pnpm', content: code('pnpm add @iconify-json/lucide') },
  ],
});
```

## 非默认起始索引

```ts
tabs({
  defaultIndex: 2,
  panels: [
    { title: '安装', content: '<p>安装并配置。</p>' },
    { title: '用法', content: '<p>导入并调用构建器。</p>' },
    { title: '进阶', content: '<p>覆盖图标与标签。</p>' },
  ],
});
```

## 参数

<PropsTable
  labels={{ prop: '参数', type: '类型', default: '默认值' }}
  type={{
    items: { type: 'string[]', description: '省略 <code>panels</code> 时的标签标题。' },
    panels: { type: 'TabPanel[]', description: '<code>{ title?, value?, content }</code>，content 可为 HTML。' },
    label: { type: 'string', default: "''", description: '标签列表前的可选分组名。' },
    defaultIndex: { type: 'number', default: '0', description: '初始激活的标签。' },
  }}
/>

## 注意

- 设置 `value` 时用作 `data-cpd-tab` 值；否则由标题推导
  （`title.toLowerCase().replace(/\s/, '-')`）。
- 无内容的纯标题模式会渲染空激活面板。
