Files
heroui-vue/apps/docs/components/tabs.md
T
maoyingjie 145a208687 docs: close documentation facts, structure and related-component mapping
HD-04 scope, against heroui ce90ea3 cn sources:

- stale/fictional content: input.md no longer claims TextField is
  unmigrated; color-field.md no longer claims ColorPicker is private;
  header.md drops the fictional Header.Root subcomponent and the stale
  'menus not migrated' wording (MenuSection label registration is now
  documented from HeaderRoot source); radio-group.md drops three copied
  CheckboxGroup wordings (variant override is Radio's, scalar emits,
  native single-value submit); input-otp.md drops the fictional
  data-complete state and lists the real missing upstream props
- toggle-button disabled row now matches the real CSS hooks
  (:disabled / [aria-disabled], with data-disabled as a marker only)
- part API / CSS classes / interactive states restored per pinned
  sources: button (full class lists + real variable-based global CSS),
  accordion (per-part tables + variant/state lists), card (per-part
  tables + variant list), switch (SwitchGroup snippet + Switch/
  SwitchGroup class lists + states), color-field Group (class list +
  states), input-otp (variant notes, global CSS, class/state lists);
  input-group gains the two upstream usage chapters
- RelatedComponents restored from the pinned componentRelationships
  (first-3, filtered against componentsMap): 64 pages rewritten,
  list-box/slider sections added, 7 empty-mapping pages' fabricated
  entries removed; RelatedShowcases left unmigrated with its real data
  inventory recorded (2 cases, showcase-site cards)
- defaults unified on implementation evidence: granularity (inferred
  day/minute) and visibleYears (full min-max span, no "or 20" fallback);
  HD-03 hand-offs resolved (trigger focus-visible noted for HD-06,
  width guards kept)
- new demos: header-collection-grouping (MenuSection/ListBoxSection
  label wiring), empty-state-collection (collection empty slot);
  empty-state page deduplicated with a boundary compatibility note
- ComponentPreview minHeight/isBgSolid restored per the 30 upstream
  marks; tabs-overflow max-w-full kept after measuring internal scroll
- tests: +3 header registration/demo cases, +1 empty-state collection
  case; full suite 110 files / 1630 tests, typecheck and build:docs
  pass
2026-10-28 22:32:10 +08:00

10 KiB
Raw Blame History

title, description, component, group
title description component group
Tabs 标签页 Tabs 将内容组织为多个区块,并允许用户在它们之间导航。 tabs 组件

固定 HeroUI 3.2.6 / ce90ea3;使用 Vue 具名部件、原生 attrs 与同源 SFC 演示。

用法

import { Tabs } from "@heroui-vue/components";

组件结构

Vue 使用具名部件导出,选择值推荐使用 value(兼容基线 id 作为逻辑 key)。

<script setup lang="ts">
import {
  Tabs,
  TabsListContainer,
  TabsList,
  TabsTab,
  TabsPanel,
  TabsIndicator,
} from "@heroui-vue/components";
</script>
<template>
  <Tabs default-value="overview">
    <TabsListContainer>
      <TabsList aria-label="选项">
        <TabsTab value="overview">
          概览
          <TabsIndicator />
        </TabsTab>
        <TabsTab value="analytics">
          分析
          <TabsIndicator />
        </TabsTab>
      </TabsList>
    </TabsListContainer>
    <TabsPanel value="overview">概览内容</TabsPanel>
    <TabsPanel value="analytics">分析内容</TabsPanel>
  </Tabs>
</template>

示例

垂直布局

溢出

当标签列表超出可用空间时,TabsListContainer 会自动渲染滚动箭头与渐隐边缘,使用户可以导航到被隐藏的标签。水平与垂直方向均支持此行为。

禁用 Tab

带分隔线

在每个 <TabsTab> 内(第一项除外)添加 <TabsSeparator />,用于在标签之间显示分隔线。

次要类型

次要类型(垂直)

对齐方式

标签内容默认居中。使用 align 可将其对齐到 start 或 end,这在垂直的侧边栏式导航中尤其有用。单个标签仍可通过 TabsTab 上的 class 覆盖。

渲染函数

自定义样式

Tailwind CSS

全局 CSS

若要自定义组件类,可使用 @layer components 指令。了解更多。

@layer components {
  .hv-tabs__list {
    @apply rounded-xl border border-border bg-surface p-1;
  }

  .hv-tabs__tab {
    @apply rounded-lg font-medium;
  }

  .hv-tabs__indicator {
    @apply rounded-lg bg-foreground shadow-sm;
  }

  .hv-tabs--secondary > .hv-tabs__list-container > .hv-tabs__list {
    @apply border-b border-border bg-transparent p-0;
  }

  .hv-tabs--secondary > .hv-tabs__list-container .hv-tabs__indicator {
    @apply rounded-none bg-accent;
  }
}

样式参考

HeroUI 遵循 BEM 方法论,确保组件变体与状态可复用且易于自定义。

CSS 类

Tabs 组件使用以下 CSS 类(查看源码样式):

基础类

  • .hv-tabs - Tabs 根容器
  • .hv-tabs__list-container - 标签列表容器外层包裹
  • .hv-tabs__list-container__scroller - 标签列表的可滚动容器(处理溢出与渐隐边缘)
  • .hv-tabs__list-container__scroll-prev - 向前(左 / 上)滚动的箭头按钮
  • .hv-tabs__list-container__scroll-next - 向后(右 / 下)滚动的箭头按钮
  • .hv-tabs__list - 标签列表容器
  • .hv-tabs__tab - 单个标签按钮
  • .hv-tabs__separator - 标签之间的分隔线
  • .hv-tabs__panel - 标签面板内容
  • .hv-tabs__indicator - 标签指示器

方向属性

  • .hv-tabs[data-orientation="horizontal"] - 水平标签布局(默认)
  • .hv-tabs[data-orientation="vertical"] - 垂直标签布局

变体类

  • .hv-tabs--secondary - 次要类型变体,使用下划线指示器

对齐类

  • .hv-tabs--align-start - 标签内容对齐到起始侧
  • .hv-tabs--align-end - 标签内容对齐到结束侧

交互状态

组件同时支持 CSS 伪类与 data 属性:

  • Selected:[aria-selected="true"]
  • Hover::hover 或 [data-hovered="true"]
  • Focus::focus-visible 或 [data-focus-visible="true"]
  • Disabled:[aria-disabled="true"]

API 参考

Tabs

Prop 类型 默认值 描述
variant "primary" | "secondary" "primary" 视觉样式变体。Primary 使用填充指示器,Secondary 使用下划线指示器
orientation "horizontal" | "vertical" "horizontal" 标签布局方向
align "start" | "center" | "end" "center" 每个标签内部内容的对齐方式
selectedKey string - 受控选中标签的 key
defaultSelectedKey string - 默认选中标签的 key
@selection-change (key: string | number) => void - 选中变化回调
class string - 附加 CSS 类
as as: string - Vue 自定义根元素类型

TabsList

Prop 类型 默认值 描述
aria-label string - 标签列表的无障碍标签
class string - 附加 CSS 类
as as: string - Vue 自定义根元素类型

TabsTab

Prop 类型 默认值 描述
id string - 标签唯一标识
isDisabled boolean false 是否禁用该标签
class string - 附加 CSS 类
as as: string - Vue 自定义根元素类型

TabsSeparator

Prop 类型 默认值 描述
class string - 附加 CSS 类

TabsPanel

Prop 类型 默认值 描述
id string - 与对应 Tab id 匹配的面板标识
class string - 附加 CSS 类
as as: string - Vue 自定义根元素类型

Vue 状态与部件补充

推荐 v-model(modelValue / update:modelValue);selectedKey / defaultSelectedKey 与 @selection-change 保留为兼容别名,modelValue/defaultValue 优先。未给默认值时选择首个未禁用项;非受控选中项删除或被禁用后回落到首个可用项。受控父级拒绝请求时保持父级选择。数值与字符串 key 区分,真实 DOM ID 按实例生成,Tab/Panel 的 value(或 id 别名)匹配。

部件 属性 / 事件 默认 说明
Tabs keyboardActivation automatic manual 时方向键仅移动焦点,Enter/Space 选择
Tabs disabledKeys / isDisabled [] / false 禁用指定项 / 全组
Tabs dir ConfigProvider 或 ltr 水平导航、逻辑位置与滚动方向
TabsList loop / as true / div 默认到达两端循环,可显式关闭
TabsListContainer as div 包含真实 ScrollShadow 与滚动箭头,非 tablist 角色
TabsTab value / id / as / href - / - / button(href 时 a) id 为逻辑 key 别名,非最终 DOM ID;disabled 与 isDisabled 均可用
TabsTab 默认作用域插槽 { isSelected, isDisabled } 替代 React render props
TabsPanel value / id / as / shouldForceMount - / - / div / false 强制挂载用于保留未选中面板状态,未选中仍隐藏
TabsIndicator as / 默认插槽 span 放在每个 Tab 内,按选中项几何位置过渡
TabsSeparator as / 默认插槽 span 装饰性分隔线

RAC 的集合 render-prop API 不作逐字复制,列表用 v-for,DOM render 用 as + 原生 attrs;未知 Vue 包装组件内的首选项/面板 SSR 无法静态发现,应显式给 defaultValue 与 ARIA。Reka 保留按下/焦点自动激活语义,监听 mousedown/keydown 可取消相应激活,不能用 click.prevent 撤销此前的自动选择。失活面板容器保留并隐藏,默认卸载内容;shouldForceMount 保留内容。

渲染函数示例以普通锚点替代 Next Link,指向本地指南/组件/介绍页;保留上游导航型示例中不匹配的面板 key,因此不展示普通内容面板。Vue Router 可通过调用者的导航事件接入,本包不强依赖路由库;as 当前接受原生标签字符串。

相关组件

Breadcrumbs 面包屑