feat: migrate ScrollShadow and Tabs with docs and keyboard support

This commit is contained in:
maoyingjie
2026-10-23 00:25:45 +08:00
parent 2b4ac04df1
commit 99df0f1c91
55 changed files with 3290 additions and 5 deletions
+11
View File
@@ -352,3 +352,14 @@ Vaul Vue 官方已说明停止维护并推荐 Reka Drawer;新项目不采用 V
- Popover 模态 closeAutoFocus 的取消能力与 Reka 有已记录差异,不在文档承诺可取消;Tooltip Provider warmup 不宣称等价 RAC 全局调度。新增能力先验证实际底座而非只改类型和表格。
- 动画测量态不能用未经规范化的 style 字符串精确比较:浏览器会把 `translate(0, -200%)` 序列化为 `translate(0px, -200%)`。把临时 `animation:none` 当成 reduced-motion 会提前删掉 entering,Popover/Tooltip 因而跳过进入动画。回归同时覆盖 CSSOM 两种写法、定位后开始及真正无动画路径;真实浏览器检查 animationstart/end 和时长,不只检查关闭后节点消失。
## M24–M25 滚动与标签页约束(2026-10-23)
- ScrollShadow 与 Tabs 已由集成人迁移,当前状态见 [M24–M25 报告](docs/migrations/M24-M25-scroll-shadow-tabs.md)。useScrollShadow 是公共能力,组件与组合式函数必须共用一份测量内核;Vue 返回属性显式绑定,不复制 React dataset 副作用。
- 滚动边界须验证 offset、1px 容差、RTL 负 scrollLeft、内容增减、资源加载、禁用/手动模式切换及卸载清理。静态容器 ResizeObserver 不足以覆盖内部内容变化;RAF 合并实际测量,别建立因自身 data 属性更新触发的观察循环。
- 不为套源 CSS 将 Reka 的 data-disabled 空字符串改成 true。RovingFocus 用空值过滤键盘候选,样式改用存在选择器;禁用样式、焦点和原生属性要一起验收。
- Reka 的内部 ID 会覆盖外层 attrs。Tabs 通过真正的 asChild 原生节点维护实例唯一的 Tab/Panel ID、显式 ARIA 和 SSR 首屏关联;字符串/数字 key 隔离。插槽预规划同时识别 kebab/camel props,并验证条件成员与嵌套 Tabs。
- 指示器按布局坐标测量,避免祖先弹层缩放改变尺寸;保留初始无过渡、后续 250ms 几何过渡、RTL 和 reduced-motion。Tab 手势与自动焦点请求须去重,受控拒绝不能让一次点击重复发选择请求。
- Markdown 表格类型中的管道符必须转义,即使包在行内代码中也不例外;浏览器核对每行单元格数及长短表铺满/无横向溢出。新增依赖同步 dependencies、external 策略与 dist 类型检查,不以源码 alias 验证代替发布产物。
- 底座的 useVModel 不能在初始无选中项时误入 passive 模式。Tabs 私有 wire key 对原始字符串/数值做类型编码,并用独立空值表示无选择;公开 key 与事件保持原值。回归初始空/全禁用→启用→受控拒绝,检查 aria-selected 与视觉标记一致。
+2
View File
@@ -80,12 +80,14 @@ const groups = [
url: "/components/progress-circle",
},
{ title: "RadioGroup 单选框组", url: "/components/radio-group" },
{ title: "ScrollShadow 滚动阴影", url: "/components/scroll-shadow" },
{ title: "SearchField 搜索框", url: "/components/search-field" },
{ title: "Separator 分隔符", url: "/components/separator" },
{ title: "Skeleton 骨架屏", url: "/components/skeleton" },
{ title: "Spinner 加载指示器", url: "/components/spinner" },
{ title: "Surface 表面", url: "/components/surface" },
{ title: "Switch 开关", url: "/components/switch" },
{ title: "Tabs 标签页", url: "/components/tabs" },
{ title: "TextArea 多行文本框", url: "/components/textarea" },
{ title: "TextField 文本输入框", url: "/components/text-field" },
{ title: "Tooltip 工具提示", url: "/components/tooltip" },
+3
View File
@@ -45,3 +45,6 @@ description: 已迁移组件及文档
- [Modal 模态框](./components/modal)
- [Popover 弹出框](./components/popover)
- [Tooltip 工具提示](./components/tooltip)
- [ScrollShadow 滚动阴影](./components/scroll-shadow)
- [Tabs 标签页](./components/tabs)
+166
View File
@@ -0,0 +1,166 @@
---
title: ScrollShadow 滚动阴影
description: 通过阴影提示可滚动溢出内容,并根据滚动位置自动检测显示或隐藏。
component: scroll-shadow
group: 组件
---
> 固定 HeroUI 3.2.6 / ce90ea3;使用 Vue 具名部件、原生 attrs 与同源 SFC 演示。
## 用法
```ts
import { ScrollShadow } from "@heroui-vue/components";
```
<ComponentPreview name="scroll-shadow-default" />
## 示例
### 方向
<ComponentPreview name="scroll-shadow-orientation" />
### 阴影尺寸
<ComponentPreview name="scroll-shadow-size" />
### 与 Card 组合
<ComponentPreview name="scroll-shadow-with-card" />
### 隐藏滚动条
<ComponentPreview name="scroll-shadow-hide-scroll-bar" />
### 可见性变化
<ComponentPreview name="scroll-shadow-visibility-change" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="scroll-shadow-custom-styles" />
### 全局 CSS
若要自定义组件类,可使用 `@layer components` 指令。[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
```css
@layer components {
.hv-scroll-shadow {
@apply rounded-xl border border-border;
}
.hv-scroll-shadow--vertical {
@apply pr-2; /* Add padding for custom scrollbar styling */
}
.hv-scroll-shadow--horizontal {
@apply pb-2;
}
}
```
## 样式参考
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
### CSS 类
ScrollShadow 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/scroll-shadow.css)):
#### 基础类
- `.hv-scroll-shadow` - 根容器元素
#### 方向变体
- `.hv-scroll-shadow--vertical` - 纵向滚动(默认)
- `.hv-scroll-shadow--horizontal` - 横向滚动
#### 状态修饰符
- `.hv-scroll-shadow--hide-scrollbar` - 隐藏原生滚动条
### CSS 变量
ScrollShadow 组件使用 CSS 变量设置渐变遮罩尺寸,并为可见的原生滚动条保留空间:
| 变量 | 默认值 | 描述 |
| -------------------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------- |
| `--scroll-shadow-size` | `40px` | 控制渐变阴影尺寸。该值由 `size` prop 设置。 |
| `--scroll-shadow-offset` | `0px` | 开始显示渐变之前需要滚动的距离。该值由 `offset` prop 设置。 |
| `--scroll-shadow-scrollbar-size` | `10px`(`hideScrollBar` 时为 `0px`) | 为原生滚动条保留一段实色遮罩区域,避免渐变覆盖滚动条。使用更宽的自定义滚动条时可以覆盖该值。 |
### Data 属性
组件使用 data 属性控制阴影可见性:
- **滚动状态**:`[data-top-scroll]`、`[data-bottom-scroll]`、`[data-left-scroll]`、`[data-right-scroll]` — 当内容可向对应方向滚动时应用
- **组合状态**:`[data-top-bottom-scroll]`、`[data-left-right-scroll]` — 当内容可向两个方向滚动时应用
- **方向**:`[data-orientation="vertical"]` 或 `[data-orientation="horizontal"]` — 表示滚动方向
- **尺寸**:`[data-scroll-shadow-size]` — 阴影渐变尺寸数值
- **阴影模式**:`[data-scroll-shadow-mode]` — 渐变由滚动位置推导时为 `"auto"`;`visibility` 受控或 `isEnabled` 为 `false` 时为 `"manual"`
### 滚动驱动的渐变
在 `auto` 模式下,支持[滚动驱动动画](https://developer.mozilla.org/zh-CN/docs/Web/CSS/animation-timeline)的浏览器会直接在 CSS
中根据滚动位置推导渐变。因此遮罩在首次绘制时就是正确的,无需测量,也不会在 hydration 期间出现未渐变内容的闪烁。
不支持的浏览器会回退到上面的 `[data-*-scroll]` 属性,这些属性在 hydration 之后才写入。自定义样式时需要注意两点:
- 在 `auto` 模式下,即使没有可滚动内容,根元素也始终会解析出 `mask-image`。这会使其成为层叠上下文,
并成为 `position: fixed` 后代元素的包含块。如需退出该行为,请显式设置 `visibility`。
- 滚动驱动的渐变依赖根元素上的 `animation` 属性。在同一元素上使用 `animate-*` 工具类会覆盖它,导致渐变消失。
请改为对外层容器应用动画。
## API 参考
### ScrollShadow
| Prop | 类型 | 默认值 | 描述 |
| -------------------- | ---------------------------------------------------------------------------------- | ------------ | ---------------------------------- |
| `orientation` | `"vertical"` \| `"horizontal"` | `"vertical"` | 滚动方向 |
| `variant` | `"fade"` | `"fade"` | 阴影视觉效果样式 |
| `size` | `number` | `40` | 阴影渐变尺寸(像素) |
| `offset` | `number` | `0` | 开始显示阴影前的滚动偏移量(像素) |
| `hideScrollBar` | `boolean` | `false` | 是否隐藏原生滚动条 |
| `isEnabled` | `boolean` | `true` | 是否启用滚动阴影检测 |
| `visibility` | `"auto"` \| `"both"` \| `"top"` \| `"bottom"` \| `"left"` \| `"right"` \| `"none"` | `"auto"` | 受控的阴影可见性 |
| `@visibility-change` | `(visibility: ScrollShadowVisibility) => void` | - | 阴影可见性变化时调用的回调 |
| `class` | `string` | - | 应用到根元素上的额外 CSS 类 |
| `默认插槽` | `VNode / 插槽` | - | 可滚动的子内容 |
## Vue 事件与测量边界
`@visibility-change` 仅在自动检测状态变化时通知;显式 visibility 控制显示,不产生自动检测事件。isEnabled=false 停止自动检测并清除旧阴影,显式 visibility 仍优先。水平 left/right 与基线一样表示逻辑起始/结束,RTL 由 CSS 交换物理边缘。偏移边界与末端 1px 容差保留。
通过 VueUse 监听尺寸、子树文本/样式/节点与资源 load,滚动测量合并到 requestAnimationFrame,卸载清理;暴露 element、update() 和 scrollTo(options)。遮罩布局/滚动由真实浏览器验证,单元测试的模拟尺寸只验证边界计算。CSS scroll timeline、首次渲染和堆叠上下文限制保留上面的源说明。默认不添加 tabIndex,需键盘滚动的独立区域请提供 tabindex="0" 和可访问名称。
## useScrollShadow
公开组合式函数复用组件的同一份测量内核,接受元素 ref/getter 和响应式 orientation / offset / visibility / isEnabled。返回只读 visibility、attributes 与 update();Vue 通过 v-bind 明确绑定状态属性,不像 React hook 隐式修改 dataset。样式与尺寸由调用者设置。
```vue
<script setup lang="ts">
import { ref } from "vue";
import { useScrollShadow } from "@heroui-vue/components";
const element = ref<HTMLElement>();
const { attributes } = useScrollShadow({ containerRef: element });
</script>
<template>
<div
ref="element"
class="hv-scroll-shadow hv-scroll-shadow--fade hv-scroll-shadow--vertical h-40"
v-bind="attributes"
data-scroll-shadow-mode="auto"
>
<!-- 可滚动内容 -->
</div>
</template>
```
## 相关组件
[ScrollShadow 滚动阴影](./scroll-shadow) · [Tabs 标签页](./tabs)
+240
View File
@@ -0,0 +1,240 @@
---
title: Tabs 标签页
description: Tabs 将内容组织为多个区块,并允许用户在它们之间导航。
component: tabs
group: 组件
---
> 固定 HeroUI 3.2.6 / ce90ea3;使用 Vue 具名部件、原生 attrs 与同源 SFC 演示。
## 用法
```ts
import { Tabs } from "@heroui-vue/components";
```
<ComponentPreview name="tabs-basic" />
## 组件结构
Vue 使用具名部件导出,选择值推荐使用 value(兼容基线 id 作为逻辑 key)。
```vue
<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>
```
## 示例
### 垂直布局
<ComponentPreview name="tabs-vertical" />
### 溢出
当标签列表超出可用空间时,`TabsListContainer` 会自动渲染滚动箭头与渐隐边缘,使用户可以导航到被隐藏的标签。水平与垂直方向均支持此行为。
<ComponentPreview name="tabs-overflow" />
### 禁用 Tab
<ComponentPreview name="tabs-disabled" />
### 带分隔线
在每个 `<TabsTab>` 内(第一项除外)添加 `<TabsSeparator />`,用于在标签之间显示分隔线。
<ComponentPreview name="tabs-with-separator" />
### 次要类型
<ComponentPreview name="tabs-secondary" />
### 次要类型(垂直)
<ComponentPreview name="tabs-secondary-vertical" />
### 对齐方式
标签内容默认居中。使用 `align` 可将其对齐到 `start` 或 `end`,这在垂直的侧边栏式导航中尤其有用。单个标签仍可通过 `TabsTab` 上的 `class` 覆盖。
<ComponentPreview name="tabs-vertical-alignment" />
### 渲染函数
<ComponentPreview name="tabs-render-function" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="tabs-custom-styles" />
### 全局 CSS
若要自定义组件类,可使用 `@layer components` 指令。[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
```css
@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](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
### CSS 类
Tabs 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/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 当前接受原生标签字符串。
## 相关组件
[ScrollShadow 滚动阴影](./scroll-shadow) · [Tabs 标签页](./tabs)
@@ -0,0 +1,31 @@
<script setup lang="ts">
import { ScrollShadow } from "@heroui-vue/components";
const entries = [
"与设计团队一起回顾季度目标。",
"将深色模式设计令牌发布到生产环境。",
"合并表单字段的无障碍修复。",
"发布更新后的组件文档。",
"安排下一冲刺的性能审计。",
"在文档站点中添加滚动阴影示例。",
];
</script>
<template>
<div class="w-full sm:max-w-sm">
<ScrollShadow
hideScrollBar
class="max-h-48 rounded-xl border border-border/80 bg-linear-to-b from-neutral-50/90 to-white p-4 ring-1 ring-black/5 dark:from-neutral-900/80 dark:to-neutral-900 dark:ring-white/10"
:size="48"
variant="fade"
>
<div class="space-y-3">
<template :key="entry" v-for="entry in entries">
<p
class="text-sm leading-relaxed text-neutral-600 dark:text-neutral-400"
>
{{ entry }}
</p>
</template>
</div>
</ScrollShadow>
</div>
</template>
+19
View File
@@ -0,0 +1,19 @@
<script setup lang="ts">
import { ScrollShadow } from "@heroui-vue/components";
</script>
<template>
<div class="w-full p-0 sm:max-w-sm">
<ScrollShadow class="max-h-[240px] p-4">
<div class="space-y-4">
<template :key="idx" v-for="(_, idx) in Array.from({ length: 10 })">
<p>
段落 {{ idx + 1 }}:Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nullam pulvinar risus non risus hendrerit
venenatis. Pellentesque sit amet hendrerit risus, sed porttitor
quam. Morbi accumsan cursus enim, sed ultricies sapien.
</p>
</template>
</div>
</ScrollShadow>
</div>
</template>
@@ -0,0 +1,19 @@
<script setup lang="ts">
import { ScrollShadow } from "@heroui-vue/components";
</script>
<template>
<div class="w-full p-0 sm:max-w-sm">
<ScrollShadow hideScrollBar class="max-h-[240px] p-4">
<div class="space-y-4">
<template :key="idx" v-for="(_, idx) in Array.from({ length: 10 })">
<p>
段落 {{ idx + 1 }}:Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nullam pulvinar risus non risus hendrerit
venenatis. Pellentesque sit amet hendrerit risus, sed porttitor
quam. Morbi accumsan cursus enim, sed ultricies sapien.
</p>
</template>
</div>
</ScrollShadow>
</div>
</template>
@@ -0,0 +1,63 @@
<script setup lang="ts">
import {
Card,
CardDescription,
CardTitle,
ScrollShadow,
} from "@heroui-vue/components";
const images = [
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/robot1.jpeg",
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/avocado.jpeg",
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/oranges.jpeg",
];
const getRandomImage = (idx: number) => {
return images[idx % images.length];
};
</script>
<template>
<div class="w-full sm:max-w-sm">
<div class="mb-8 w-full">
<h4 class="mb-2 text-sm font-semibold">垂直</h4>
<Card class="w-full p-0">
<ScrollShadow class="max-h-[240px] p-4" orientation="vertical">
<div class="space-y-4">
<template :key="idx" v-for="(_, idx) in Array.from({ length: 10 })">
<p>
段落 {{ idx + 1 }}:Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nullam pulvinar risus non risus hendrerit
venenatis. Pellentesque sit amet hendrerit risus, sed porttitor
quam. Morbi accumsan cursus enim, sed ultricies sapien.
</p>
</template>
</div>
</ScrollShadow>
</Card>
</div>
<div class="w-full">
<h4 class="mb-2 text-sm font-semibold">水平</h4>
<Card class="w-full p-0">
<ScrollShadow class="p-4" orientation="horizontal">
<div class="flex flex-row gap-4">
<template :key="idx" v-for="(_, idx) in Array.from({ length: 10 })">
<Card
class="flex min-w-[200px] flex-row gap-3 p-1"
variant="transparent"
>
<img
alt="示例卡片"
class="aspect-square h-16 w-16 shrink-0 rounded-xl object-cover select-none sm:h-20 sm:w-20"
loading="lazy"
:src="getRandomImage(idx)"
/>
<div class="flex flex-1 flex-col justify-center gap-1">
<CardTitle class="text-sm">连接未来</CardTitle>
<CardDescription class="text-xs">今天 18:30</CardDescription>
</div>
</Card>
</template>
</div>
</ScrollShadow>
</Card>
</div>
</div>
</template>
+19
View File
@@ -0,0 +1,19 @@
<script setup lang="ts">
import { ScrollShadow } from "@heroui-vue/components";
</script>
<template>
<div class="w-full p-0 sm:max-w-sm">
<ScrollShadow class="max-h-[240px] p-4" :size="80">
<div class="space-y-4">
<template :key="idx" v-for="(_, idx) in Array.from({ length: 10 })">
<p>
段落 {{ idx + 1 }}:Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nullam pulvinar risus non risus hendrerit
venenatis. Pellentesque sit amet hendrerit risus, sed porttitor
quam. Morbi accumsan cursus enim, sed ultricies sapien.
</p>
</template>
</div>
</ScrollShadow>
</div>
</template>
@@ -0,0 +1,98 @@
<script setup lang="ts">
import type { ScrollShadowVisibility } from "@heroui-vue/components";
import { ref } from "vue";
import {
Card,
CardDescription,
CardTitle,
ScrollShadow,
} from "@heroui-vue/components";
const images = [
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/robot1.jpeg",
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/avocado.jpeg",
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/oranges.jpeg",
];
const VISIBILITY_LABELS: Record<ScrollShadowVisibility, string> = {
auto: "自动",
both: "两侧",
bottom: "底部",
left: "左侧",
none: "无",
right: "右侧",
top: "顶部",
};
const verticalState = ref<ScrollShadowVisibility>("none");
function setVerticalState(value: ScrollShadowVisibility) {
verticalState.value = value;
}
const horizontalState = ref<ScrollShadowVisibility>("none");
function setHorizontalState(value: ScrollShadowVisibility) {
horizontalState.value = value;
}
const getRandomImage = (idx: number) => {
return images[idx % images.length];
};
</script>
<template>
<div class="w-full sm:max-w-sm">
<div class="mb-8 flex flex-col gap-2">
<div class="rounded bg-default p-4">
<p class="text-sm font-semibold">
垂直阴影状态:{{ VISIBILITY_LABELS[verticalState] }}
</p>
</div>
<div class="w-full">
<ScrollShadow
class="max-h-[240px] p-4"
orientation="vertical"
@visibility-change="(visibility) => setVerticalState(visibility)"
>
<div class="space-y-4">
<template :key="idx" v-for="(_, idx) in Array.from({ length: 10 })">
<p>
段落 {{ idx + 1 }}:Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nullam pulvinar risus non risus hendrerit
venenatis. Pellentesque sit amet hendrerit risus, sed porttitor
quam. Morbi accumsan cursus enim, sed ultricies sapien.
</p>
</template>
</div>
</ScrollShadow>
</div>
</div>
<div class="flex flex-col gap-2">
<div class="rounded bg-default p-4">
<p class="text-sm font-semibold">
水平阴影状态:{{ VISIBILITY_LABELS[horizontalState] }}
</p>
</div>
<div class="w-full">
<ScrollShadow
class="p-4"
orientation="horizontal"
@visibility-change="(visibility) => setHorizontalState(visibility)"
>
<div class="flex flex-row gap-4">
<template :key="idx" v-for="(_, idx) in Array.from({ length: 10 })">
<Card
class="flex min-w-[200px] flex-row gap-3 p-1"
variant="transparent"
>
<img
alt="示例卡片"
class="aspect-square h-16 w-16 shrink-0 rounded-xl object-cover select-none sm:h-20 sm:w-20"
loading="lazy"
:src="getRandomImage(idx)"
/>
<div class="flex flex-1 flex-col justify-center gap-1">
<CardTitle class="text-sm">连接未来</CardTitle>
<CardDescription class="text-xs">今天 18:30</CardDescription>
</div>
</Card>
</template>
</div>
</ScrollShadow>
</div>
</div>
</div>
</template>
@@ -0,0 +1,38 @@
<script setup lang="ts">
import {
Button,
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
ScrollShadow,
} from "@heroui-vue/components";
</script>
<template>
<Card class="max-w-[400px]">
<CardHeader>
<CardTitle>条款与条件</CardTitle>
<CardDescription>继续前请先阅读</CardDescription>
</CardHeader>
<CardContent class="p-0">
<ScrollShadow class="h-[300px] px-4" :size="80">
<div class="space-y-4">
<template :key="idx" v-for="(_, idx) in Array.from({ length: 10 })">
<p>
段落 {{ idx + 1 }}:Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nullam pulvinar risus non risus hendrerit
venenatis. Pellentesque sit amet hendrerit risus, sed porttitor
quam. Morbi accumsan cursus enim, sed ultricies sapien.
</p>
</template>
</div>
</ScrollShadow>
</CardContent>
<CardFooter class="mt-4 flex flex-row gap-2">
<Button class="w-full" variant="secondary">Cancel</Button>
<Button class="w-full">接受</Button>
</CardFooter>
</Card>
</template>
+39
View File
@@ -0,0 +1,39 @@
<script setup lang="ts">
import {
Tabs,
TabsIndicator,
TabsList,
TabsListContainer,
TabsPanel,
TabsTab,
} from "@heroui-vue/components";
</script>
<template>
<Tabs class="w-full max-w-md">
<TabsListContainer>
<TabsList aria-label="选项">
<TabsTab value="overview">
概览
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="analytics">
分析
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="reports">
报告
<TabsIndicator></TabsIndicator>
</TabsTab>
</TabsList>
</TabsListContainer>
<TabsPanel class="pt-4" value="overview">
<p>查看项目概览与近期活动。</p>
</TabsPanel>
<TabsPanel class="pt-4" value="analytics">
<p>跟踪指标并分析性能数据。</p>
</TabsPanel>
<TabsPanel class="pt-4" value="reports">
<p>生成并下载详细报告。</p>
</TabsPanel>
</Tabs>
</template>
+51
View File
@@ -0,0 +1,51 @@
<script setup lang="ts">
import {
Tabs,
TabsIndicator,
TabsList,
TabsListContainer,
TabsPanel,
TabsTab,
} from "@heroui-vue/components";
const listClassName = [
"rounded-xl border border-accent/10 bg-accent-soft/30 p-1",
"**:data-[slot=tabs-tab]:rounded-lg",
"**:data-[slot=tabs-tab]:bg-transparent",
"**:data-[slot=tabs-tab]:text-muted",
"**:data-[slot=tabs-tab]:opacity-100",
"**:data-[slot=tabs-tab]:transition-colors",
"**:data-[slot=tabs-tab]:data-[hovered=true]:not-data-[selected=true]:bg-accent-soft",
"**:data-[slot=tabs-tab]:data-[hovered=true]:not-data-[selected=true]:text-accent-soft-foreground",
"**:data-[slot=tabs-tab]:data-[pressed=true]:not-data-[selected=true]:bg-accent-soft-hover",
"**:data-[slot=tabs-tab]:data-[focus-visible=true]:ring-2",
"**:data-[slot=tabs-tab]:data-[focus-visible=true]:ring-accent/15",
"**:data-[slot=tabs-tab]:data-[selected=true]:font-medium",
"**:data-[slot=tabs-tab]:data-[selected=true]:text-accent-foreground",
"**:data-[slot=tabs-tab]:shadow-none",
"**:data-[slot=tabs-indicator]:rounded-lg",
"**:data-[slot=tabs-indicator]:bg-accent",
"**:data-[slot=tabs-indicator]:shadow-none",
].join(" ");
</script>
<template>
<Tabs class="w-full max-w-sm">
<TabsListContainer class="rounded-none bg-transparent">
<TabsList aria-label="计费周期" :class="listClassName">
<TabsTab value="monthly">
按月
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="yearly">
按年
<TabsIndicator></TabsIndicator>
</TabsTab>
</TabsList>
</TabsListContainer>
<TabsPanel class="pt-3 text-sm text-muted" value="monthly">
按月计费,随时可取消。
</TabsPanel>
<TabsPanel class="pt-3 text-sm text-muted" value="yearly">
年付可节省 20%。
</TabsPanel>
</Tabs>
</template>
+37
View File
@@ -0,0 +1,37 @@
<script setup lang="ts">
import {
Tabs,
TabsIndicator,
TabsList,
TabsListContainer,
TabsPanel,
TabsTab,
} from "@heroui-vue/components";
</script>
<template>
<Tabs class="w-full max-w-md">
<TabsListContainer>
<TabsList aria-label="含禁用项的标签页">
<TabsTab value="active">
启用
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab isDisabled value="disabled">
已禁用
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="available">
可用
<TabsIndicator></TabsIndicator>
</TabsTab>
</TabsList>
</TabsListContainer>
<TabsPanel class="pt-4" value="active">
<p>此标签页已启用,可以选择。</p>
</TabsPanel>
<TabsPanel class="pt-4" value="disabled"><p>无法访问此内容。</p></TabsPanel>
<TabsPanel class="pt-4" value="available">
<p>此标签页也可以选择。</p>
</TabsPanel>
</Tabs>
</template>
+42
View File
@@ -0,0 +1,42 @@
<script setup lang="ts">
import {
Tabs,
TabsIndicator,
TabsList,
TabsListContainer,
TabsPanel,
TabsTab,
} from "@heroui-vue/components";
const items = [
{ id: "overview", label: "概览" },
{ id: "analytics", label: "分析" },
{ id: "reports", label: "报告" },
{ id: "performance", label: "性能" },
{ id: "engagement", label: "互动" },
{ id: "audience", label: "受众" },
{ id: "acquisition", label: "获取" },
{ id: "retention", label: "留存" },
{ id: "settings", label: "设置" },
];
</script>
<template>
<div class="w-[400px] max-w-full">
<Tabs>
<TabsListContainer>
<TabsList aria-label="溢出选项">
<template :key="item.id" v-for="item in items">
<TabsTab :value="item.id">
{{ item.label }}
<TabsIndicator></TabsIndicator>
</TabsTab>
</template>
</TabsList>
</TabsListContainer>
<template :key="item.id" v-for="item in items">
<TabsPanel class="pt-4" :value="item.id">
<p>{{ item.label }} 面板内容。</p>
</TabsPanel>
</template>
</Tabs>
</div>
</template>
+39
View File
@@ -0,0 +1,39 @@
<script setup lang="ts">
import {
Tabs,
TabsIndicator,
TabsList,
TabsListContainer,
TabsPanel,
TabsTab,
} from "@heroui-vue/components";
</script>
<template>
<Tabs class="w-full max-w-md" as="div" data-custom="foo">
<TabsListContainer>
<TabsList aria-label="选项">
<TabsTab href="/guide" value="getting-started" as="a">
快速入门
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab href="/components" value="components" as="a">
组件
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab href="/introduction" value="releases" as="a">
发布说明
<TabsIndicator></TabsIndicator>
</TabsTab>
</TabsList>
</TabsListContainer>
<TabsPanel class="pt-4" value="overview">
<p>查看项目概览与近期活动。</p>
</TabsPanel>
<TabsPanel class="pt-4" value="analytics">
<p>跟踪指标并分析性能数据。</p>
</TabsPanel>
<TabsPanel class="pt-4" value="reports">
<p>生成并下载详细报告。</p>
</TabsPanel>
</Tabs>
</template>
@@ -0,0 +1,50 @@
<script setup lang="ts">
import {
Tabs,
TabsIndicator,
TabsList,
TabsListContainer,
TabsPanel,
TabsTab,
} from "@heroui-vue/components";
</script>
<template>
<Tabs class="w-full max-w-lg" orientation="vertical" variant="secondary">
<TabsListContainer>
<TabsList aria-label="垂直标签页">
<TabsTab value="account">
账户
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="security">
安全
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="notifications">
通知
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="billing">
账单
<TabsIndicator></TabsIndicator>
</TabsTab>
</TabsList>
</TabsListContainer>
<TabsPanel class="px-4" value="account">
<h3 class="mb-2 font-semibold">账户 Settings</h3>
<p class="text-sm text-muted">管理你的账户信息与偏好设置。</p>
</TabsPanel>
<TabsPanel class="px-4" value="security">
<h3 class="mb-2 font-semibold">安全 Settings</h3>
<p class="text-sm text-muted">配置双重认证与密码设置。</p>
</TabsPanel>
<TabsPanel class="px-4" value="notifications">
<h3 class="mb-2 font-semibold">通知偏好</h3>
<p class="text-sm text-muted">选择接收通知的方式与时间。</p>
</TabsPanel>
<TabsPanel class="px-4" value="billing">
<h3 class="mb-2 font-semibold">账单 Information</h3>
<p class="text-sm text-muted">查看并管理订阅与支付方式。</p>
</TabsPanel>
</Tabs>
</template>
+39
View File
@@ -0,0 +1,39 @@
<script setup lang="ts">
import {
Tabs,
TabsIndicator,
TabsList,
TabsListContainer,
TabsPanel,
TabsTab,
} from "@heroui-vue/components";
</script>
<template>
<Tabs class="w-full max-w-md" variant="secondary">
<TabsListContainer>
<TabsList aria-label="选项">
<TabsTab value="overview">
概览
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="analytics">
分析
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="reports">
报告
<TabsIndicator></TabsIndicator>
</TabsTab>
</TabsList>
</TabsListContainer>
<TabsPanel class="pt-4" value="overview">
<p>查看项目概览与近期活动。</p>
</TabsPanel>
<TabsPanel class="pt-4" value="analytics">
<p>跟踪指标并分析性能数据。</p>
</TabsPanel>
<TabsPanel class="pt-4" value="reports">
<p>生成并下载详细报告。</p>
</TabsPanel>
</Tabs>
</template>
@@ -0,0 +1,63 @@
<script setup lang="ts">
import {
Tabs,
TabsIndicator,
TabsList,
TabsListContainer,
TabsPanel,
TabsTab,
} from "@heroui-vue/components";
</script>
<template>
<Tabs
align="start"
class="w-full max-w-lg"
orientation="vertical"
variant="secondary"
>
<TabsListContainer>
<TabsList aria-label="设置">
<TabsTab value="general">
通用
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="billing">
订阅与账单
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="appearance">
外观
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="notifications">
通知
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="privacy">
隐私
<TabsIndicator></TabsIndicator>
</TabsTab>
</TabsList>
</TabsListContainer>
<TabsPanel class="px-4" value="general">
<h3 class="mb-2 font-semibold">通用</h3>
<p class="text-sm text-muted">管理你的账户信息与偏好设置。</p>
</TabsPanel>
<TabsPanel class="px-4" value="billing">
<h3 class="mb-2 font-semibold">订阅与账单</h3>
<p class="text-sm text-muted">查看并管理你的套餐与支付方式。</p>
</TabsPanel>
<TabsPanel class="px-4" value="appearance">
<h3 class="mb-2 font-semibold">外观</h3>
<p class="text-sm text-muted">选择主题并调整界面密度。</p>
</TabsPanel>
<TabsPanel class="px-4" value="notifications">
<h3 class="mb-2 font-semibold">通知</h3>
<p class="text-sm text-muted">选择接收通知的方式与时间。</p>
</TabsPanel>
<TabsPanel class="px-4" value="privacy">
<h3 class="mb-2 font-semibold">隐私</h3>
<p class="text-sm text-muted">控制你分享的内容以及谁可以查看你的动态。</p>
</TabsPanel>
</Tabs>
</template>
+50
View File
@@ -0,0 +1,50 @@
<script setup lang="ts">
import {
Tabs,
TabsIndicator,
TabsList,
TabsListContainer,
TabsPanel,
TabsTab,
} from "@heroui-vue/components";
</script>
<template>
<Tabs class="w-full max-w-lg" orientation="vertical">
<TabsListContainer>
<TabsList aria-label="垂直标签页">
<TabsTab value="account">
账户
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="security">
安全
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="notifications">
通知
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="billing">
账单
<TabsIndicator></TabsIndicator>
</TabsTab>
</TabsList>
</TabsListContainer>
<TabsPanel class="px-4" value="account">
<h3 class="mb-2 font-semibold">账户 Settings</h3>
<p class="text-sm text-muted">管理你的账户信息与偏好设置。</p>
</TabsPanel>
<TabsPanel class="px-4" value="security">
<h3 class="mb-2 font-semibold">安全 Settings</h3>
<p class="text-sm text-muted">配置双重认证与密码设置。</p>
</TabsPanel>
<TabsPanel class="px-4" value="notifications">
<h3 class="mb-2 font-semibold">通知偏好</h3>
<p class="text-sm text-muted">选择接收通知的方式与时间。</p>
</TabsPanel>
<TabsPanel class="px-4" value="billing">
<h3 class="mb-2 font-semibold">账单 Information</h3>
<p class="text-sm text-muted">查看并管理订阅与支付方式。</p>
</TabsPanel>
</Tabs>
</template>
+42
View File
@@ -0,0 +1,42 @@
<script setup lang="ts">
import {
Tabs,
TabsIndicator,
TabsList,
TabsListContainer,
TabsPanel,
TabsSeparator,
TabsTab,
} from "@heroui-vue/components";
</script>
<template>
<Tabs class="w-full max-w-md">
<TabsListContainer>
<TabsList aria-label="选项">
<TabsTab value="overview">
概览
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="analytics">
<TabsSeparator></TabsSeparator>
分析
<TabsIndicator></TabsIndicator>
</TabsTab>
<TabsTab value="reports">
<TabsSeparator></TabsSeparator>
报告
<TabsIndicator></TabsIndicator>
</TabsTab>
</TabsList>
</TabsListContainer>
<TabsPanel class="pt-4" value="overview">
<p>查看项目概览与近期活动。</p>
</TabsPanel>
<TabsPanel class="pt-4" value="analytics">
<p>跟踪指标并分析性能数据。</p>
</TabsPanel>
<TabsPanel class="pt-4" value="reports">
<p>生成并下载详细报告。</p>
</TabsPanel>
</Tabs>
</template>
+6 -1
View File
@@ -1,5 +1,9 @@
<script setup lang="ts">
import { ref } from "vue";
import ScrollTabsLab from "./ScrollTabsLab.vue";
const scrollTabsLab =
typeof window !== "undefined" &&
new URLSearchParams(window.location.search).has("scroll-tabs");
import OverlayAnimationLab from "./OverlayAnimationLab.vue";
const animationLab =
typeof window !== "undefined" &&
@@ -23,7 +27,8 @@ function save() {
}
</script>
<template>
<OverlayAnimationLab v-if="animationLab" />
<ScrollTabsLab v-if="scrollTabsLab" />
<OverlayAnimationLab v-else-if="animationLab" />
<OverlayComponentsLab v-else-if="componentsLab" />
<OverlayLab v-else-if="overlayLab" />
<div v-else class="lab" :data-theme="dark ? 'dark' : 'light'">
+57
View File
@@ -0,0 +1,57 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
ScrollShadow,
Tabs,
TabsListContainer,
TabsList,
TabsTab,
TabsPanel,
TabsIndicator,
} from "@heroui-vue/components";
const dir = ref<"ltr" | "rtl">("ltr"),
orientation = ref<"horizontal" | "vertical">("horizontal"),
count = ref(1);
const keys = Array.from({ length: 12 }, (_, i) => `tab-${i + 1}`);
</script>
<template>
<main class="p-8 flex flex-col gap-6">
<h1>ScrollShadow / Tabs 集成回归</h1>
<div class="flex gap-4">
<Button @click="dir = dir === 'ltr' ? 'rtl' : 'ltr'">切换 RTL</Button>
<Button
@click="
orientation = orientation === 'horizontal' ? 'vertical' : 'horizontal'
"
>
切换方向
</Button>
<Button @click="count = count === 1 ? 12 : 1">切换内容数量</Button>
</div>
<output>{{ dir }} / {{ orientation }} / {{ count }}</output>
<Tabs :dir="dir" :orientation="orientation" class="w-full max-w-xl">
<TabsListContainer
:class="orientation === 'horizontal' ? 'w-[320px]' : 'h-[160px] w-32'"
>
<TabsList aria-label="方向溢出">
<TabsTab v-for="key in keys" :key="key" :value="key">
{{ key }}
<TabsIndicator />
</TabsTab>
</TabsList>
</TabsListContainer>
<TabsPanel v-for="key in keys" :key="key" :value="key">
{{ key }} 内容
</TabsPanel>
</Tabs>
<ScrollShadow
class="h-32 w-64"
tabindex="0"
role="region"
aria-label="动态滚动内容"
>
<p v-for="i in count" :key="i" class="h-12">段落 {{ i }}</p>
</ScrollShadow>
</main>
</template>
+6 -2
View File
@@ -38,7 +38,7 @@
| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap |
| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 |
| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 |
| scroll-shadow | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 |
| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator |
| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 |
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
@@ -47,7 +47,7 @@
| toggle-button | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
| tabs | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| toggle-button-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
@@ -190,3 +190,7 @@ React render 自定义根类型不支持;原生 attrs/具名部件/作用域
## Modal / Popover / Tooltip(OVERLAY-02)
公共部件、源 CSS/tv、中文文档、14 + 6 + 6 个基线演示与类型/行为回归已迁移;详情见 [OVERLAY-02 报告](./migrations/OVERLAY-02-modal-popover-tooltip.md)。框架适配采用 Vue 具名组件、v-model:open、as/asChild、原生事件与作用域插槽;不承诺 React PressEvent。Popover 模态 closeAutoFocus 继承 Reka 无条件恢复触发器的策略,取消恢复需非模态模式;Tooltip warmup 由 ConfigProvider 范围共享,非 RAC 全局调度。SSR Portal 挂载后插入。未声明逐像素、全部读屏/触屏/RTL、Nuxt 或独立打包安装验收。
## M24–M25 ScrollShadow / Tabs(2026-10-23)
7/7 与 10/10 固定基线预览已迁移。复用 VueUse 观察和 Reka Tabs,未引入集合/滚动/焦点的第二套全局协议。公开 useScrollShadow 返回只读状态/属性供 Vue 绑定;Tabs 使用具名部件、v-model、作用域插槽和实例唯一 ID。失活面板保留隐藏容器而卸载内容,shouldForceMount 可保留内容。RAC render 集合、Next Link、私有自动 ID/SelectionIndicator 机制采用 Vue 方式替代;具体行为和未验收边界见 [M24–M25 报告](./migrations/M24-M25-scroll-shadow-tabs.md)。
+4
View File
@@ -238,3 +238,7 @@ overlay 私有实现、useOverlayState 与 ConfigProvider 由集成人维护;
## OVERLAY-02 集成完成后的边界
Modal / Popover / Tooltip 公共迁移与全部 26 个基线预览已接入,差异和验证见 [OVERLAY-02](./migrations/OVERLAY-02-modal-popover-tooltip.md)。共享入口、providers/composables、overlay 私有实现与三个家族归集成人;ScrollShadow → Tabs 仍可作为其他 AI 的独立批次,不代表已派发。新弹层/集合任务必须先复用现有协议,并交出焦点/名称/退出/嵌套的失败场景,不能另造全局栈。
## M24–M25 集成完成(2026-10-23)
用户改为由集成人继续实施,ScrollShadow → Tabs 已迁移,不再作为待派发任务。实际交付与差异见 [M24–M25](./migrations/M24-M25-scroll-shadow-tabs.md)。后续集合/菜单任务复用现有弹层、字段与滚动设施;共享入口仍由单一编辑者集成。两个工程组件的 keyboardActivation、data-disabled、ID、指示器测量、ScrollShadow 公共 hook 需保留回归;不能把演示组件数量当作完整兼容验收。
@@ -0,0 +1,31 @@
# M24–M25:ScrollShadow / Tabs
2026-10-23;起始提交 2b4ac04(Modal/Popover/Tooltip)。固定 HeroUI 3.2.6 / ce90ea3,由集成人继续迁移;状态为验证中,不声明全兼容或逐像素完成。
## 交付
- ScrollShadow / useScrollShadow:fade、方向、40px 默认尺寸、offset、隐藏滚动条、自动/显式可见性、isEnabled 与 visibilityChange。RAF 合并读数,复用 VueUse 的尺寸/子树/事件观察,资源 load 也触发测量,卸载清理。暴露 element/update/scrollTo。
- Tabs / TabsListContainer / TabsList / TabsTab / TabsIndicator / TabsPanel / TabsSeparator:两个变体、方向/对齐、v-model 与 selectedKey 别名、默认选择、disabledKeys、automatic/manual 键盘激活、Home/End/方向键、滚动箭头及 250ms 指示器过渡。复用 Reka Tabs/RovingFocus/Presence,兼容逻辑 id 别名,生成实例唯一真实 DOM ID。
- 完整移植两份 CSS/tv;中文文档、实际导航、全部 7 + 10 个源示例、API/样式说明、复制/高亮共用的 SFC。结构代码另有编译挂载;表格沿公共铺满/换行规则。
- VueUse 14.4.0 为精确直接依赖并 external,未新增第二套交互库。工程页 ?scroll-tabs 提供 RTL/方向切换、垂直溢出与动态内容回归。
## Vue 差异
- 模型为 modelValue/update:modelValue(v-model),兼容 selectedKey/defaultSelectedKey/@selection-change;默认值仅初始化。未定义受控值时使用本地默认/首个启用项;失去选中成员后回落到首个启用项。字符串与数值身份保留。
- React 对象子部件和 render-prop 集合改为具名部件、v-for 与作用域插槽;DOM render 改为原生 as 字符串 + attrs。Next Link 示例使用本地指南/组件/介绍页的普通锚点,未加入 Vue Router;保留上游导航型示例不匹配的内容 key。
- TabsTab/Panel 的 id 是逻辑值别名,不是最终 DOM ID;显式 aria-controls/labelledby 可透传。SSR 静态预规划覆盖已知部件/原生/Fragment,任意未知 Vue 包装内需显式 defaultValue/ARIA,未承诺自动展开全部用户组件。
- 失活面板容器保留并隐藏,默认卸载其内容,shouldForceMount 保留内容。指示器使用真实布局坐标与 CSS 过渡;未复刻 RAC 的私有 SelectionIndicator 运行时、路由与集合导出。
- Reka 空 data-disabled 是键盘协议,CSS 存在选择器替代 RAC 的 true 值。保留按下/键盘激活,自动焦点经薄适配去重,受控父级拒绝时一次指针手势只请求一次。click.prevent 不能撤销此前 mousedown 激活;可取消相应 mousedown/keydown。
- useScrollShadow 接受响应式 ref/getter,返回 readonly visibility、attributes、update;调用者 v-bind 属性,区别于 React hook 隐式写 dataset。显式 visibility 优先于禁用检测,不自动发检测事件。水平 left/right 表示逻辑前后边缘;CSS scroll timeline/首次绘制/堆叠上下文限制原样说明。
## 验证
- pnpm test:24 文件 / 394 项(含独立 node SSR 11 项与 jsdom 实际水合)。pnpm test:unit:23 文件 / 383 项。新批次 13 个行为/全量演示/水合测试,另加 node SSR 1 项。
- typecheck、build:docs、build:playground、format、git diff --check 通过;文档仅既有 chunk 提醒。源码和 dist 声明正反消费覆盖值类型/变体/事件;临时 dist 探针删除,不算独立安装。
- 5173 浏览器抽查:Tabs primary 选择与面板、250ms 指示器、secondary 垂直 2px 边线、禁用跳过、横向箭头 clamp 到末端;ScrollShadow 240px 内容容器/遮罩;API 长短表无横向溢出(桌面 736px、390px 窄屏 350px,所有行维持四列,页面 scrollWidth 等于 viewport);最终 console warn/error 为 0。截图 /tmp/heroui-vue-tabs-final.png 为 1280×720 浅色。
- 5175 ?scroll-tabs:RTL 负向滚动、160px 垂直溢出、内容从 1 → 12 → 1 自动重测并清除阴影。键盘与真实滚动验证,未逐个点击全部演示。
- 未建立自动逐像素、完整读屏/触屏、全部浏览器 RTL、Nuxt Teleport/水合或打包后独立安装验收。JS 测试尺寸模拟只验证状态边界,不作为真实布局证据。
## 本批发现并关闭的问题
Reka ID 覆盖外层关联、asChild 的未选中面板容器被一并卸载、预规划漏掉 kebab 禁用属性、将 data-disabled 改成 true 破坏方向键过滤、API 表的未转义管道、受控拒绝时重复选择请求、初始空/全禁用时底座误入非受控、禁用后重新启用导致旧选中项复活,均已修复并回归。布局测量保留 offset 坐标,避免祖先缩放引入错误。
+8
View File
@@ -117,3 +117,11 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
- 中文文档与 demos/cn/{modal,popover,tooltip}:14/6/6 个基线预览、介绍/结构/样式/API;模板代码与预览共用 SFC。表单例增加真实 FormData 反馈,框架差异另行说明。
- tw-animate-css 1.4.0(与固定上游一致)提供源样式依赖的动画 utilities,未引入另一套动画运行时;MIT 许可证保存为 third-party/TW-ANIMATE-CSS-LICENSE 和 packages/styles/LICENSE.tw-animate-css。库与文档编译入口均导入,保持独立构建。
- Reka UI 2.11.0 负责 Dialog/Popover/Tooltip/Portal/Presence/FocusScope 的真实运行时。Tooltip 仅适配其现有 tooltip.open 协调事件,不复制全局焦点或关闭栈。具体差异见 OVERLAY-02 报告。
## M24–M25 来源(2026-10-23)
- 固定 HeroUI ce90ea3 的 packages/react/src/components/{scroll-shadow,tabs}:部件/属性、滚动边界(offset 与末端 1px 容差)、RTL 滚动箭头的 80% 步进与 clamp。
- 同名 CSS/tv 完整移植为 hv- 命名空间;ScrollShadow 关键帧改名避免冲突,CSS 自定义变量保留。Tabs 禁用选择器适配 Reka 的空 data-disabled,不能改动该值破坏底层键盘候选过滤。Apache-2.0 来源头和原许可证保留。
- CN components/(utilities)/scroll-shadow.mdx 与 (navigation)/tabs.mdx,demos/cn/scroll-shadow(7 例)、tabs(10 例):文案、次序、结构与样式;预览/复制/高亮仍共用 SFC。内置四向 Chevron 路径直接来自固定 icons.tsx,非自绘演示图标。
- VueUse core 14.4.0(MIT,既有锁文件版本新增为直接依赖),使用 ResizeObserver/MutationObserver/事件工具,库产物 external 并由 dependencies 声明;未复制 VueUse 实现。Reka 2.11.0 的 Tabs/RovingFocus/Presence 保留为交互底座。
- React SelectionIndicator 改为共享布局测量与各 Tab 的装饰性指示器,保持 250ms ease-out-fluid 的 translate/width/height 过渡。布局坐标避免祖先 Modal 缩放污染测量。React hook 改为 Vue 响应式输入与 attributes 显式绑定。
+11
View File
@@ -467,3 +467,14 @@ typecheck、build:docs、build:playground、format、diff-check 通过;文档
## OVERLAY-02 动画专项复核
修复测量 transform 的 CSSOM px 规范化导致 Popover/Tooltip 跳过进入动画。真实浏览器事件及帧采样确认 Modal 遮罩/内容 150/250ms、Popover/Tooltip 进入 150ms、浮层退出 100ms,曲线与源 CSS 一致;详细对照见 OVERLAY-02 报告。新增 3 项测试,pnpm test 23 文件 / 380 项(含 node SSR 10);typecheck、build:docs、build:playground、format 与 diff-check 通过。未运行完整 React 站并排录像,未据此声明逐像素一致。
## M24–M25 ScrollShadow / Tabs(2026-10-23)
详细验证及边界见 [M24–M25](./migrations/M24-M25-scroll-shadow-tabs.md)。全部 17 个基线演示编译挂载,新增滚动/选择/禁用/键盘/受控/ID/SSR 实际水合验证。
| 命令 | 文件 | 通过 | 范围 |
| -------------- | ---- | ---- | -------------------------------- |
| pnpm test | 24 | 394 | 含 node SSR 11 与 jsdom 实际水合 |
| pnpm test:unit | 23 | 383 | 不含 node SSR |
typecheck、build:docs、build:playground、format、diff-check 与 dist 正反类型消费通过。浏览器重点验证横向末端/RTL/垂直溢出、动态增减内容、禁用跳过、指示器和文档表格。未声明完整读屏/触屏、自动逐像素、Nuxt 或打包后独立安装。
+1 -1
View File
@@ -15,7 +15,7 @@
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
"typecheck": "vue-tsc --noEmit",
"test": "vitest run",
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts",
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts",
"test:ssr": "vitest run tests/ssr.test.ts",
"format": "prettier --check .",
"format:fix": "prettier --write .",
@@ -0,0 +1,215 @@
/* Adapted from HeroUI ce90ea3, Apache-2.0. See third-party/HEROUI-LICENSE. */
/* Base scroll-shadow component */
.hv-scroll-shadow {
@apply relative;
--scroll-shadow-size: 40px;
--scroll-shadow-scrollbar-size: 10px;
--scroll-shadow-offset: 0px;
}
/* Fade sizes for the scroll-driven variant below. They stay at 0px whenever the scroll
timeline is inactive, which is exactly the state of a container without overflow. */
@property --scroll-shadow-start-fade {
syntax: "<length>";
inherits: false;
initial-value: 0px;
}
@property --scroll-shadow-end-fade {
syntax: "<length>";
inherits: false;
initial-value: 0px;
}
@keyframes hv-scroll-shadow-start-fade {
from {
--scroll-shadow-start-fade: 0px;
}
to {
--scroll-shadow-start-fade: var(--scroll-shadow-size);
}
}
@keyframes hv-scroll-shadow-end-fade {
from {
--scroll-shadow-end-fade: var(--scroll-shadow-size);
}
to {
--scroll-shadow-end-fade: 0px;
}
}
/* Orientation: Vertical */
.hv-scroll-shadow--vertical {
@apply scrollbar overflow-y-auto;
}
/* Orientation: Horizontal */
.hv-scroll-shadow--horizontal {
@apply scrollbar overflow-x-auto;
}
/* Variant: Fade - Vertical */
.hv-scroll-shadow--fade.hv-scroll-shadow--vertical {
/* `[data-scroll-shadow-mode="auto"]` lets the scroll-driven variant below reuse this
plumbing. It only paints once `--scroll-linear-gradient` is set, since an undefined
variable makes `mask-image` invalid at computed-value time, which resolves to `none`. */
&:where(
[data-top-scroll="true"],
[data-bottom-scroll="true"],
[data-top-bottom-scroll="true"],
[data-scroll-shadow-mode="auto"]
) {
mask-image:
linear-gradient(var(--scroll-linear-gradient)),
linear-gradient(#000, #000);
mask-position:
left top,
right top;
mask-repeat: no-repeat;
mask-size:
calc(100% - var(--scroll-shadow-scrollbar-size)) 100%,
var(--scroll-shadow-scrollbar-size) 100%;
-webkit-mask-image:
linear-gradient(var(--scroll-linear-gradient)),
linear-gradient(#000, #000);
-webkit-mask-position:
left top,
right top;
-webkit-mask-repeat: no-repeat;
-webkit-mask-size:
calc(100% - var(--scroll-shadow-scrollbar-size)) 100%,
var(--scroll-shadow-scrollbar-size) 100%;
}
&[data-top-scroll="true"] {
--scroll-linear-gradient:
0deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
}
&[data-bottom-scroll="true"] {
--scroll-linear-gradient:
180deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
}
&[data-top-bottom-scroll="true"] {
--scroll-linear-gradient:
#000, #000, transparent 0, #000 var(--scroll-shadow-size),
#000 calc(100% - var(--scroll-shadow-size)), transparent;
}
}
/* Variant: Fade - Horizontal */
.hv-scroll-shadow--fade.hv-scroll-shadow--horizontal {
&:where(
[data-left-scroll="true"],
[data-right-scroll="true"],
[data-left-right-scroll="true"],
[data-scroll-shadow-mode="auto"]
) {
mask-image:
linear-gradient(var(--scroll-linear-gradient)),
linear-gradient(#000, #000);
mask-position:
left top,
left bottom;
mask-repeat: no-repeat;
mask-size:
100% calc(100% - var(--scroll-shadow-scrollbar-size)),
100% var(--scroll-shadow-scrollbar-size);
-webkit-mask-image:
linear-gradient(var(--scroll-linear-gradient)),
linear-gradient(#000, #000);
-webkit-mask-position:
left top,
left bottom;
-webkit-mask-repeat: no-repeat;
-webkit-mask-size:
100% calc(100% - var(--scroll-shadow-scrollbar-size)),
100% var(--scroll-shadow-scrollbar-size);
}
/* `left`/`right` data attributes are logical (before/end of scroll). In RTL the
start edge is on the right, so the physical fade direction must be swapped. */
&[data-left-scroll="true"] {
--scroll-linear-gradient:
270deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
&:dir(rtl) {
--scroll-linear-gradient:
90deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
}
}
&[data-right-scroll="true"] {
--scroll-linear-gradient:
90deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
&:dir(rtl) {
--scroll-linear-gradient:
270deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
}
}
&[data-left-right-scroll="true"] {
--scroll-linear-gradient:
to right, #000, #000, transparent 0, #000 var(--scroll-shadow-size),
#000 calc(100% - var(--scroll-shadow-size)), transparent;
}
}
.hv-scroll-shadow--hide-scrollbar {
@apply scrollbar-none;
--scroll-shadow-scrollbar-size: 0px;
}
/* Variant: Fade - scroll-driven
Where scroll timelines are available the fade is derived from the real scroll state,
so it is already correct on the first paint and needs no measurement or hydration.
A container without overflow has an inactive timeline, which leaves both fades at 0px
and collapses the mask to a no-op. The attribute-driven rules above remain the
fallback for engines without scroll timelines, and keep serving controlled mode.
Two consequences of deriving the mask from CSS alone:
- Auto mode always resolves a `mask-image`, even with nothing to scroll, so the root is
always a stacking context and a containing block for fixed descendants. Gating that on
overflow would need a measurement, which is the flicker this variant exists to avoid.
- The `animation` shorthand here lives in the components layer, so an `animate-*` utility
on the root replaces it and pins both fades at 0px, leaving no fade at all. */
@supports (animation-timeline: scroll(self)) {
/* `.scroll-shadow` is repeated so these rules outrank the attribute-driven gradients
above on specificity rather than on source order, which a re-ordering could break. */
.hv-scroll-shadow.hv-scroll-shadow--fade[data-scroll-shadow-mode="auto"] {
animation:
hv-scroll-shadow-start-fade linear both,
hv-scroll-shadow-end-fade linear both;
animation-range:
var(--scroll-shadow-offset)
calc(var(--scroll-shadow-offset) + var(--scroll-shadow-size)),
calc(100% - var(--scroll-shadow-size) - var(--scroll-shadow-offset))
calc(100% - var(--scroll-shadow-offset));
}
/* The orientation rules also outrank the `animation` shorthand above, which resets
`animation-timeline` to `auto`, so the timeline survives regardless of order. */
.hv-scroll-shadow.hv-scroll-shadow--fade.hv-scroll-shadow--vertical[data-scroll-shadow-mode="auto"] {
animation-timeline: scroll(self block), scroll(self block);
--scroll-linear-gradient:
180deg, transparent 0, #000 var(--scroll-shadow-start-fade),
#000 calc(100% - var(--scroll-shadow-end-fade)), transparent 100%;
}
.hv-scroll-shadow.hv-scroll-shadow--fade.hv-scroll-shadow--horizontal[data-scroll-shadow-mode="auto"] {
animation-timeline: scroll(self inline), scroll(self inline);
--scroll-linear-gradient:
90deg, transparent 0, #000 var(--scroll-shadow-start-fade),
#000 calc(100% - var(--scroll-shadow-end-fade)), transparent 100%;
/* Inline-axis progress starts at the right edge in RTL, so flip the physical direction */
&:dir(rtl) {
--scroll-linear-gradient:
270deg, transparent 0, #000 var(--scroll-shadow-start-fade),
#000 calc(100% - var(--scroll-shadow-end-fade)), transparent 100%;
}
}
}
+303
View File
@@ -0,0 +1,303 @@
/* Adapted from HeroUI ce90ea3, Apache-2.0. See third-party/HEROUI-LICENSE. */
/* Base tabs component */
.hv-tabs {
@apply flex gap-2;
/* Orientation styles */
&[data-orientation="horizontal"] {
@apply flex-col;
}
&[data-orientation="vertical"] {
@apply flex-row;
}
}
/* Tab list container */
.hv-tabs__list-container {
@apply relative bg-default;
border-radius: calc(var(--radius) * 2.5);
/* Vertical scroller fills the container height so overflow detection
engages when the wrapper height is constrained (e.g. h-[240px]) */
> .hv-tabs__list-container__scroller[data-orientation="vertical"] {
@apply h-full;
}
/* Overflow chevron buttons */
> .hv-tabs__list-container__scroll-prev,
> .hv-tabs__list-container__scroll-next {
@apply absolute z-2 hidden size-4 cursor-(--cursor-interactive) items-center justify-center rounded-full border-0 bg-transparent p-0 text-foreground outline-none;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition: opacity 150ms var(--ease-smooth);
@apply motion-reduce:transition-none;
@media (hover: hover) {
&:hover {
@apply opacity-70;
}
}
&:focus-visible {
@apply status-focused;
}
}
/* Chevron position - horizontal orientation */
&:has([data-orientation="horizontal"]) {
> .hv-tabs__list-container__scroll-prev {
@apply start-1 top-1/2 -translate-y-1/2;
}
> .hv-tabs__list-container__scroll-next {
@apply end-1 top-1/2 -translate-y-1/2;
}
> .hv-tabs__list-container__scroll-prev,
> .hv-tabs__list-container__scroll-next {
@apply rtl:rotate-180;
}
}
/* Chevron position - vertical orientation */
&:has([data-orientation="vertical"]) {
> .hv-tabs__list-container__scroll-prev {
@apply top-1 left-1/2 -translate-x-1/2;
}
> .hv-tabs__list-container__scroll-next {
@apply bottom-1 left-1/2 -translate-x-1/2;
}
}
/* Show chevrons only when ScrollShadow reports scrolling is possible */
&:has(
> :is(
[data-left-scroll="true"],
[data-left-right-scroll="true"],
[data-top-scroll="true"],
[data-top-bottom-scroll="true"]
)
)
> .hv-tabs__list-container__scroll-prev {
@apply inline-flex;
}
&:has(
> :is(
[data-right-scroll="true"],
[data-left-right-scroll="true"],
[data-bottom-scroll="true"],
[data-top-bottom-scroll="true"]
)
)
> .hv-tabs__list-container__scroll-next {
@apply inline-flex;
}
}
/* Tab list */
.hv-tabs__list {
@apply inline-flex p-1;
/* Horizontal orientation - grow with content so ScrollShadow can detect overflow */
&[data-orientation="horizontal"] {
@apply w-max min-w-full flex-row;
}
/* Vertical orientation */
&[data-orientation="vertical"] {
@apply flex-col gap-1;
.hv-tabs__tab {
@apply min-w-20;
}
}
}
/* Individual tab */
.hv-tabs__tab {
@apply relative flex h-8 w-full items-center justify-center rounded-3xl px-4 text-center text-sm font-medium text-muted outline-none no-highlight;
z-index: 1;
cursor: var(--cursor-interactive);
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
color 150ms var(--ease-smooth),
background-color 150ms var(--ease-smooth),
box-shadow 150ms var(--ease-out),
opacity 150ms var(--ease-smooth);
@apply motion-reduce:transition-none;
/* Selected state */
&[data-selected="true"] {
@apply text-segment-foreground;
/* Hide separator on the selected tab and the one following it */
.hv-tabs__separator,
& + .hv-tabs__tab .hv-tabs__separator {
@apply opacity-0;
}
}
/* Disabled state */
&:disabled,
&[data-disabled],
&[aria-disabled="true"] {
@apply status-disabled;
}
/* Hover states - both approaches for compatibility */
@media (hover: hover) {
&:not([data-selected="true"]):not([data-disabled]):hover,
&[data-hovered="true"]:not([data-selected="true"]):not([data-disabled]) {
@apply opacity-70;
}
}
/* Focus states - comprehensive fallback */
&:focus-visible:not([data-focused]),
&[data-focus-visible="true"] {
@apply status-focused;
}
}
/* Tab content alignment - center is the default, handled by .hv-tabs__tab.
Scoped to the direct child holding the tab list (the list container, or the
list itself when Tabs.ListContainer is omitted) so a nested Tabs inside a
panel keeps its own alignment. */
.hv-tabs--align-start
> :is(.hv-tabs__list-container, .hv-tabs__list)
.hv-tabs__tab {
@apply justify-start text-start;
}
.hv-tabs--align-end
> :is(.hv-tabs__list-container, .hv-tabs__list)
.hv-tabs__tab {
@apply justify-end text-end;
}
/* Tab separator */
.hv-tabs__separator {
@apply pointer-events-none absolute rounded-sm bg-muted/25;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition: opacity 150ms var(--ease-smooth);
@apply motion-reduce:transition-none;
/* Horizontal tabs - vertical separator */
.hv-tabs__list[data-orientation="horizontal"] & {
@apply start-0 top-1/4 h-1/2 w-px;
}
/* Vertical tabs - horizontal separator */
.hv-tabs__list[data-orientation="vertical"] & {
@apply start-[5%] top-0 h-px w-[90%];
}
}
/* Tab panel */
.hv-tabs__panel {
@apply w-full p-2 outline-none;
/* Exiting animations */
&[data-exiting="true"] {
@apply absolute start-0 top-0 w-full;
}
/* Orientation spacing */
&[data-orientation="horizontal"] {
@apply mt-4;
}
&[data-orientation="vertical"] {
@apply ms-4;
}
}
/* Tab indicator - React Aria's SelectionIndicator */
.hv-tabs__indicator {
@apply absolute start-0 top-0 size-full rounded-3xl bg-segment shadow-surface;
z-index: -1;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition-duration: 250ms;
transition-property: translate, width, height;
transition-timing-function: var(--ease-out-fluid);
@apply motion-reduce:transition-none;
}
/* ==========================================================================
Secondary Variant
========================================================================== */
.hv-tabs--secondary {
/* Container - flat, no pill. Underline on container (not list) so it stays
stable when the inner list scrolls horizontally inside the ScrollShadow. */
> .hv-tabs__list-container {
@apply rounded-none bg-transparent;
/* Tab list - remove padding */
.hv-tabs__list {
@apply p-0;
}
/* Hide separators in secondary variant */
.hv-tabs__separator {
@apply hidden;
}
/* Tab - adjust for secondary variant */
.hv-tabs__tab {
@apply rounded-none;
/* Selected state - use text-foreground */
&[data-selected="true"] {
@apply text-foreground;
}
}
/* Tab indicator - line style */
.hv-tabs__indicator {
@apply rounded-none bg-accent shadow-none;
}
}
/* Horizontal orientation - bottom border + bottom line indicator */
&[data-orientation="horizontal"] > .hv-tabs__list-container {
@apply border-b border-border;
.hv-tabs__indicator {
@apply top-auto bottom-0 h-0.5;
}
}
/* Vertical orientation - left border + left line indicator */
&[data-orientation="vertical"] > .hv-tabs__list-container {
@apply border-s border-border;
.hv-tabs__indicator {
@apply start-0 top-0 h-full w-0.5;
}
}
}
/* Reka roving-focus navigation requires an empty data-disabled marker.
* Match its presence instead of changing it to RAC boolean strings. */
+3
View File
@@ -127,3 +127,6 @@
@import "./components/popover.css" layer(components);
@import "./components/tooltip.css" layer(components);
@import "./components/scroll-shadow.css";
@import "./components/tabs.css";
+78
View File
@@ -978,3 +978,81 @@ export const tooltipVariants = tv({
});
export type TooltipVariants = VariantProps<typeof tooltipVariants>;
export const scrollShadowVariants = tv({
defaultVariants: {
hideScrollBar: false,
orientation: "vertical",
variant: "fade",
},
slots: {
base: "hv-scroll-shadow",
},
variants: {
hideScrollBar: {
false: {},
true: {
base: "hv-scroll-shadow--hide-scrollbar",
},
},
orientation: {
horizontal: {
base: "hv-scroll-shadow--horizontal",
},
vertical: {
base: "hv-scroll-shadow--vertical",
},
},
variant: {
fade: {
base: "hv-scroll-shadow--fade",
},
},
},
});
export type ScrollShadowVariants = VariantProps<typeof scrollShadowVariants>;
export const tabsVariants = tv({
defaultVariants: {
align: "center",
variant: "primary",
},
slots: {
base: "hv-tabs",
scrollNext: "hv-tabs__list-container__scroll-next",
scrollPrev: "hv-tabs__list-container__scroll-prev",
scroller: "hv-tabs__list-container__scroller",
separator: "hv-tabs__separator",
tab: "hv-tabs__tab",
tabIndicator: "hv-tabs__indicator",
tabList: "hv-tabs__list",
tabListContainer: "hv-tabs__list-container",
tabPanel: "hv-tabs__panel",
},
variants: {
align: {
center: {}, // No class as the base already centers tab content
end: {
base: "hv-tabs--align-end",
},
start: {
base: "hv-tabs--align-start",
},
},
variant: {
primary: {},
secondary: {
base: "hv-tabs--secondary",
},
},
},
});
// Render props that should be excluded from TabsVariants (framework-specific)
type TabsRenderPropsKeys = "selectedKey";
export type TabsVariants = Omit<
VariantProps<typeof tabsVariants>,
TabsRenderPropsKeys
>;
+1
View File
@@ -20,6 +20,7 @@
},
"dependencies": {
"@heroui-vue/styles": "workspace:*",
"@vueuse/core": "14.4.0",
"reka-ui": "^2.11.0"
},
"peerDependencies": {
@@ -0,0 +1,65 @@
<script setup lang="ts">
import { ref } from "vue";
import { useScrollShadow } from "./useScrollShadow";
import { scrollShadowVariants } from "@heroui-vue/styles";
import type { ScrollShadowVisibility } from "./types";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
orientation?: "vertical" | "horizontal";
variant?: "fade";
hideScrollBar?: boolean;
size?: number;
offset?: number;
visibility?: ScrollShadowVisibility;
isEnabled?: boolean;
}>(),
{
orientation: "vertical",
variant: "fade",
hideScrollBar: false,
size: 40,
offset: 0,
visibility: "auto",
isEnabled: true,
},
);
const emit = defineEmits<{
visibilityChange: [visibility: ScrollShadowVisibility];
}>();
const element = ref<HTMLElement>();
const { attributes: states, update: measure } = useScrollShadow({
containerRef: element,
orientation: () => props.orientation,
visibility: () => props.visibility,
offset: () => props.offset,
isEnabled: () => props.isEnabled,
onVisibilityChange: (value) => emit("visibilityChange", value),
});
defineExpose({
element,
update: measure,
scrollTo: (options: ScrollToOptions) => element.value?.scrollTo(options),
});
</script>
<template>
<div
ref="element"
:class="
scrollShadowVariants({ orientation, variant, hideScrollBar }).base()
"
:style="{
'--scroll-shadow-size': `${size}px`,
'--scroll-shadow-offset': `${offset}px`,
}"
v-bind="{ ...$attrs, ...states }"
:data-orientation="orientation"
:data-scroll-shadow-mode="
isEnabled && visibility === 'auto' ? 'auto' : 'manual'
"
:data-scroll-shadow-size="size"
data-slot="scroll-shadow"
>
<slot />
</div>
</template>
@@ -0,0 +1,2 @@
export type ScrollShadowVisibility =
"auto" | "both" | "top" | "bottom" | "left" | "right" | "none";
@@ -0,0 +1,119 @@
import {
computed,
ref,
watch,
onScopeDispose,
toValue,
type MaybeRefOrGetter,
} from "vue";
import {
useEventListener,
useMutationObserver,
useResizeObserver,
} from "@vueuse/core";
import type { ScrollShadowVisibility } from "./types";
export interface UseScrollShadowProps {
containerRef: MaybeRefOrGetter<HTMLElement | null | undefined>;
orientation?: MaybeRefOrGetter<"vertical" | "horizontal">;
visibility?: MaybeRefOrGetter<ScrollShadowVisibility>;
offset?: MaybeRefOrGetter<number>;
isEnabled?: MaybeRefOrGetter<boolean>;
onVisibilityChange?: (visibility: ScrollShadowVisibility) => void;
}
/** Vue counterpart of the fixed HeroUI scroll measurement hook; bind attributes to the scroll root. */
export function useScrollShadow(options: UseScrollShadowProps) {
const element = computed(() => toValue(options.containerRef));
const orientation = computed(
() => toValue(options.orientation) ?? "vertical",
);
const visibility = computed(() => toValue(options.visibility) ?? "auto");
const offset = computed(() => toValue(options.offset) ?? 0);
const isEnabled = computed(() => toValue(options.isEnabled) ?? true);
const detected = ref<ScrollShadowVisibility>("none");
const current = computed(() =>
visibility.value !== "auto"
? visibility.value
: isEnabled.value
? detected.value
: "none",
);
let frame: number | undefined;
let previous: ScrollShadowVisibility | undefined;
function measure() {
if (
frame !== undefined ||
!element.value ||
!isEnabled.value ||
visibility.value !== "auto"
)
return;
frame = requestAnimationFrame(() => {
frame = undefined;
const el = element.value;
if (!el || !isEnabled.value || visibility.value !== "auto") return;
const vertical = orientation.value === "vertical";
const start = vertical ? el.scrollTop : Math.abs(el.scrollLeft);
const before = start > offset.value;
const after =
start + (vertical ? el.clientHeight : el.clientWidth) + offset.value <
(vertical ? el.scrollHeight : el.scrollWidth) - 1;
const value =
before && after
? "both"
: before
? vertical
? "top"
: "left"
: after
? vertical
? "bottom"
: "right"
: "none";
detected.value = value;
if (value !== previous) {
previous = value;
options.onVisibilityChange?.(value);
}
});
}
watch(
() => [orientation.value, visibility.value, isEnabled.value, offset.value],
() => {
if (frame !== undefined) cancelAnimationFrame(frame);
frame = undefined;
previous = undefined;
detected.value = "none";
measure();
},
{ flush: "post" },
);
useEventListener(element, "scroll", measure, { passive: true });
useEventListener(element, "load", measure, { capture: true });
useResizeObserver(element, measure);
useMutationObserver(element, measure, {
attributes: true,
attributeFilter: ["class", "style", "dir"],
childList: true,
characterData: true,
subtree: true,
});
watch(element, measure, { flush: "post" });
onScopeDispose(() => {
if (frame !== undefined) cancelAnimationFrame(frame);
});
const states = computed(() => {
const v = current.value;
return {
"data-top-scroll": v === "top" ? "true" : undefined,
"data-bottom-scroll": v === "bottom" ? "true" : undefined,
"data-left-scroll": v === "left" ? "true" : undefined,
"data-right-scroll": v === "right" ? "true" : undefined,
"data-top-bottom-scroll":
v === "both" && orientation.value === "vertical" ? "true" : undefined,
"data-left-right-scroll":
v === "both" && orientation.value === "horizontal" ? "true" : undefined,
};
});
return { visibility: current, attributes: states, update: measure };
}
+256
View File
@@ -0,0 +1,256 @@
import {
computed,
defineComponent,
h,
provide,
ref,
shallowRef,
shallowReactive,
useId,
watch,
onBeforeUnmount,
type PropType,
type VNode,
Fragment,
isVNode,
mergeProps,
} from "vue";
import { TabsRoot } from "reka-ui";
import { useMutationObserver, useResizeObserver } from "@vueuse/core";
import { tabsVariants } from "@heroui-vue/styles";
import { useConfig } from "../../providers/context";
import { tabsKey, tabsWireKey, type TabsKey, type TabBox } from "./context";
function members(
nodes: VNode[],
output: { tabs: { key: TabsKey; disabled: boolean }[]; panels: Set<TabsKey> },
) {
for (const node of nodes) {
if (!isVNode(node)) continue;
const name =
typeof node.type === "object"
? ((node.type as { name?: string; __name?: string }).name ??
(node.type as { __name?: string }).__name)
: "";
if (name === "Tabs") continue;
const key = node.props?.value ?? node.props?.id;
if (name === "TabsTab" && key !== undefined)
output.tabs.push({
key,
disabled:
node.props?.isDisabled === "" ||
node.props?.["is-disabled"] === "" ||
!!node.props?.["is-disabled"] ||
!!node.props?.isDisabled ||
!!node.props?.disabled,
});
if (name === "TabsPanel" && key !== undefined) output.panels.add(key);
if (Array.isArray(node.children))
members(node.children.filter(isVNode), output);
else if (
["TabsListContainer", "TabsList"].includes(name || "") &&
node.children &&
typeof node.children === "object" &&
"default" in node.children
) {
const slot = node.children.default;
if (typeof slot === "function") members(slot(), output);
}
}
}
export default defineComponent({
name: "Tabs",
inheritAttrs: false,
props: {
modelValue: [String, Number] as PropType<TabsKey>,
selectedKey: [String, Number] as PropType<TabsKey>,
defaultValue: [String, Number] as PropType<TabsKey>,
defaultSelectedKey: [String, Number] as PropType<TabsKey>,
orientation: {
type: String as PropType<"horizontal" | "vertical">,
default: "horizontal",
},
variant: {
type: String as PropType<"primary" | "secondary">,
default: "primary",
},
align: {
type: String as PropType<"start" | "center" | "end">,
default: "center",
},
keyboardActivation: {
type: String as PropType<"automatic" | "manual">,
default: "automatic",
},
disabledKeys: {
type: Array as PropType<readonly TabsKey[]>,
default: () => [],
},
isDisabled: Boolean,
dir: String as PropType<"ltr" | "rtl">,
as: { type: String, default: "div" },
},
emits: {
"update:modelValue": (key: TabsKey) =>
typeof key === "string" || typeof key === "number",
"update:selectedKey": (key: TabsKey) =>
typeof key === "string" || typeof key === "number",
selectionChange: (key: TabsKey) =>
typeof key === "string" || typeof key === "number",
},
setup(props, { attrs, slots, emit }) {
const config = useConfig(),
base = useId();
const local = ref<TabsKey | undefined>(
props.defaultValue ?? props.defaultSelectedKey,
);
const options = shallowRef<{ key: TabsKey; disabled: boolean }[]>([]);
const panels = shallowRef(new Set<TabsKey>());
const disabled = (key: TabsKey) =>
props.isDisabled ||
props.disabledKeys.includes(key) ||
!!options.value.find((t) => t.key === key)?.disabled;
const selected = computed(
() =>
props.modelValue ??
props.selectedKey ??
(local.value !== undefined &&
(!options.value.length ||
options.value.some((t) => t.key === local.value && !disabled(t.key)))
? local.value
: options.value.find((t) => !disabled(t.key))?.key),
);
// Persist a reconciliation so re-enabling a removed/disabled default tab
// does not resurrect a selection the user already lost.
watch(
() => [options.value, ...props.disabledKeys, props.isDisabled],
() => {
if (props.modelValue !== undefined || props.selectedKey !== undefined)
return;
if (
!options.value.some((t) => t.key === local.value && !disabled(t.key))
)
local.value = options.value.find((t) => !disabled(t.key))?.key;
},
{ flush: "sync" },
);
const dir = computed(() => props.dir ?? config?.dir.value ?? "ltr");
function select(key: TabsKey) {
if (disabled(key) || key === selected.value) return;
if (props.modelValue === undefined && props.selectedKey === undefined)
local.value = key;
emit("update:modelValue", key);
emit("update:selectedKey", key);
emit("selectionChange", key);
}
const list = ref<HTMLElement>();
const elements = shallowReactive(new Map<TabsKey, HTMLElement>());
const boxes = shallowRef(new Map<TabsKey, TabBox>());
const ready = ref(false);
let frame: number | undefined;
function measure() {
const next = new Map<TabsKey, TabBox>();
for (const [key, el] of elements)
if (el.isConnected) {
// Layout coordinates remain stable while an ancestor Modal is scaling.
next.set(key, {
x: el.offsetLeft,
y: el.offsetTop,
width: el.offsetWidth,
height: el.offsetHeight,
});
}
if (
next.size !== boxes.value.size ||
[...next].some(([key, b]) => {
const old = boxes.value.get(key);
return (
!old ||
old.x !== b.x ||
old.y !== b.y ||
old.width !== b.width ||
old.height !== b.height
);
})
)
boxes.value = next;
if (!ready.value && next.size && frame === undefined)
frame = requestAnimationFrame(() => {
frame = undefined;
ready.value = true;
});
}
useResizeObserver(
computed(() =>
[list.value, ...elements.values()].filter(
(el): el is HTMLElement => !!el,
),
),
measure,
);
useMutationObserver(list, measure, {
childList: true,
subtree: true,
characterData: true,
attributes: true,
attributeFilter: ["class", "dir"],
});
watch(() => [props.orientation, dir.value], measure, { flush: "post" });
onBeforeUnmount(() => {
if (frame !== undefined) cancelAnimationFrame(frame);
});
provide(tabsKey, {
selected,
keyboardActivation: computed(() => props.keyboardActivation),
select,
orientation: computed(() => props.orientation),
variant: computed(() => props.variant),
dir,
disabled,
domId: (kind, key) =>
`hv-tabs-${base}-${kind}-${typeof key}-${encodeURIComponent(String(key))}`,
panels,
list,
elements,
boxes,
ready,
measure,
});
return () => {
const nodes = slots.default?.({ selectedKey: selected.value }) ?? [];
const found = {
tabs: [] as { key: TabsKey; disabled: boolean }[],
panels: new Set<TabsKey>(),
};
members(nodes, found);
if (JSON.stringify(found.tabs) !== JSON.stringify(options.value))
options.value = found.tabs;
if (
found.panels.size !== panels.value.size ||
[...found.panels].some((key) => !panels.value.has(key))
)
panels.value = found.panels;
return h(
TabsRoot,
mergeProps(attrs, {
as: props.as,
modelValue: tabsWireKey(selected.value),
"onUpdate:modelValue": (key: string | number) => {
if (typeof key !== "string") return;
if (key.startsWith("n:")) select(Number(key.slice(2)));
else if (key.startsWith("s:")) select(key.slice(2));
},
orientation: props.orientation,
activationMode: "manual",
unmountOnHide: false,
dir: dir.value,
class: tabsVariants({
variant: props.variant,
align: props.align,
}).base(),
"data-slot": "tabs",
}),
{ default: () => nodes },
);
};
},
});
@@ -0,0 +1,41 @@
<script setup lang="ts">
import { computed } from "vue";
import { useTabs, useTabKey } from "./context";
defineOptions({ inheritAttrs: false });
withDefaults(defineProps<{ as?: string }>(), { as: "span" });
const ctx = useTabs(),
key = useTabKey();
const selected = computed(() => ctx.selected.value === key.value);
const style = computed(() => {
const active =
ctx.selected.value === undefined
? undefined
: ctx.boxes.value.get(ctx.selected.value);
const own = ctx.boxes.value.get(key.value);
const secondary = ctx.variant.value === "secondary",
vertical = ctx.orientation.value === "vertical";
return {
visibility: selected.value ? ("visible" as const) : ("hidden" as const),
transition: ctx.ready.value ? undefined : "none",
...(active && own
? {
translate: `${ctx.dir.value === "rtl" ? active.x + active.width - own.x - own.width : active.x - own.x}px ${active.y - own.y}px`,
width: secondary && vertical ? undefined : `${active.width}px`,
height: secondary && !vertical ? undefined : `${active.height}px`,
}
: {}),
};
});
</script>
<template>
<component
:is="as"
v-bind="$attrs"
class="hv-tabs__indicator"
data-slot="tabs-indicator"
aria-hidden="true"
:style="style"
>
<slot />
</component>
</template>
@@ -0,0 +1,36 @@
<script setup lang="ts">
import { watch, onBeforeUnmount } from "vue";
import { TabsList as RekaList, useForwardExpose } from "reka-ui";
import { useTabs } from "./context";
defineOptions({ inheritAttrs: false });
withDefaults(defineProps<{ as?: string; loop?: boolean }>(), {
as: "div",
loop: true,
});
const ctx = useTabs();
const { forwardRef, currentElement } = useForwardExpose();
watch(
currentElement,
(el) => {
ctx.list.value = el;
ctx.measure();
},
{ flush: "post" },
);
onBeforeUnmount(() => {
ctx.list.value = undefined;
});
</script>
<template>
<RekaList
:ref="forwardRef"
v-bind="$attrs"
:as="as"
:loop="loop"
class="hv-tabs__list"
data-slot="tabs-list"
:data-orientation="ctx.orientation.value"
>
<slot />
</RekaList>
</template>
@@ -0,0 +1,93 @@
<script setup lang="ts">
import { computed, ref, watch, nextTick } from "vue";
import ScrollShadow from "../scroll-shadow/ScrollShadow.vue";
import { useTabs } from "./context";
import TabsScrollIcon from "./TabsScrollIcon.vue";
defineOptions({ inheritAttrs: false });
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
const ctx = useTabs();
const scroller = ref<InstanceType<typeof ScrollShadow>>();
const vertical = computed(() => ctx.orientation.value === "vertical");
function scroll(direction: 1 | -1) {
const el = scroller.value?.element;
if (!el) return;
const size = vertical.value ? el.clientHeight : el.clientWidth;
const max = Math.max(
0,
(vertical.value ? el.scrollHeight : el.scrollWidth) - size,
);
const rtl = !vertical.value && getComputedStyle(el).direction === "rtl";
const current = vertical.value ? el.scrollTop : el.scrollLeft;
const target = Math.min(
rtl ? 0 : max,
Math.max(rtl ? -max : 0, current + direction * size * 0.8 * (rtl ? -1 : 1)),
);
const reduce = el.ownerDocument.defaultView?.matchMedia?.(
"(prefers-reduced-motion: reduce)",
).matches;
el.scrollTo({
behavior: reduce ? "instant" : "smooth",
[vertical.value ? "top" : "left"]: target,
});
}
watch(ctx.selected, async (key) => {
await nextTick();
const el = scroller.value?.element;
const tab = key === undefined ? undefined : ctx.elements.get(key);
if (!el || !tab) return;
const box = el.getBoundingClientRect(),
target = tab.getBoundingClientRect();
const delta = vertical.value
? target.top < box.top
? target.top - box.top
: target.bottom > box.bottom
? target.bottom - box.bottom
: 0
: target.left < box.left
? target.left - box.left
: target.right > box.right
? target.right - box.right
: 0;
if (delta)
el.scrollBy({
[vertical.value ? "top" : "left"]: delta,
behavior: "instant",
});
});
</script>
<template>
<component
:is="as"
v-bind="$attrs"
class="hv-tabs__list-container"
data-slot="tabs-list-container"
>
<ScrollShadow
ref="scroller"
hide-scroll-bar
:size="64"
:orientation="ctx.orientation.value"
class="hv-tabs__list-container__scroller"
>
<slot />
</ScrollShadow>
<button
type="button"
tabindex="-1"
:aria-label="vertical ? 'Scroll tabs up' : 'Scroll tabs left'"
class="hv-tabs__list-container__scroll-prev"
@click="scroll(-1)"
>
<TabsScrollIcon :direction="vertical ? 'up' : 'left'" />
</button>
<button
type="button"
tabindex="-1"
:aria-label="vertical ? 'Scroll tabs down' : 'Scroll tabs right'"
class="hv-tabs__list-container__scroll-next"
@click="scroll(1)"
>
<TabsScrollIcon :direction="vertical ? 'down' : 'right'" />
</button>
</component>
</template>
@@ -0,0 +1,53 @@
<script setup lang="ts">
import { computed } from "vue";
import { TabsContent, useForwardExpose } from "reka-ui";
import { useTabs, tabsWireKey, type TabsKey } from "./context";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
value?: TabsKey;
id?: TabsKey;
as?: string;
shouldForceMount?: boolean;
}>(),
{ as: "div", shouldForceMount: false },
);
const ctx = useTabs();
const value = computed(() => {
const v = props.value ?? props.id;
if (v === undefined)
throw new Error("TabsPanel requires value (or id alias).");
return v;
});
const { forwardRef } = useForwardExpose();
</script>
<template>
<TabsContent
:ref="forwardRef"
v-bind="$attrs"
:value="tabsWireKey(value)"
as-child
:as="as"
:force-mount="shouldForceMount"
:hidden="ctx.selected.value !== value"
class="hv-tabs__panel"
data-slot="tabs-panel"
:data-orientation="ctx.orientation.value"
>
<component
:is="as"
:id="ctx.domId('panel', value)"
:hidden="ctx.selected.value !== value"
:aria-labelledby="
'aria-labelledby' in $attrs
? ($attrs['aria-labelledby'] as string)
: ctx.domId('tab', value)
"
>
<slot
v-if="shouldForceMount || ctx.selected.value === value"
:is-selected="ctx.selected.value === value"
/>
</component>
</TabsContent>
</template>
@@ -0,0 +1,28 @@
<script setup lang="ts">
/* Chevron paths from HeroUI ce90ea3 icons.tsx, Apache-2.0. */
defineProps<{ direction: "up" | "down" | "left" | "right" }>();
const paths = {
up: "M13.03 10.53a.75.75 0 0 1-1.06 0L8 6.56l-3.97 3.97a.75.75 0 0 1-1.06-1.06l4.5-4.5a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1 0 1.06",
down: "M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06",
left: "M10.53 2.97a.75.75 0 0 1 0 1.06L6.56 8l3.97 3.97a.75.75 0 1 1-1.06 1.06l-4.5-4.5a.75.75 0 0 1 0-1.06l4.5-4.5a.75.75 0 0 1 1.06 0",
right:
"M5.47 2.97a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 1 1-1.06-1.06L9.44 8 5.47 4.03a.75.75 0 0 1 0-1.06Z",
};
</script>
<template>
<svg
aria-hidden="true"
role="presentation"
fill="none"
width="16"
height="16"
viewBox="0 0 16 16"
>
<path
:d="paths[direction]"
fill="currentColor"
fill-rule="evenodd"
clip-rule="evenodd"
/>
</svg>
</template>
@@ -0,0 +1,15 @@
<script setup lang="ts">
defineOptions({ inheritAttrs: false });
withDefaults(defineProps<{ as?: string }>(), { as: "span" });
</script>
<template>
<component
:is="as"
v-bind="$attrs"
class="hv-tabs__separator"
data-slot="tabs-separator"
aria-hidden="true"
>
<slot />
</component>
</template>
@@ -0,0 +1,126 @@
<script setup lang="ts">
import { computed, onMounted, onBeforeUnmount, provide, ref, watch } from "vue";
import { TabsTrigger, useForwardExpose } from "reka-ui";
import { useTabs, tabsWireKey, tabKey, type TabsKey } from "./context";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
value?: TabsKey;
id?: TabsKey;
isDisabled?: boolean;
disabled?: boolean;
as?: string;
href?: string;
}>(),
{ isDisabled: false, disabled: false },
);
const ctx = useTabs();
const value = computed(() => {
const key = props.value ?? props.id;
if (key === undefined)
throw new Error("TabsTab requires value (or the compatibility id alias).");
return key;
});
provide(tabKey, value);
const disabled = computed(
() => props.isDisabled || props.disabled || ctx.disabled(value.value),
);
const selected = computed(() => ctx.selected.value === value.value);
const { forwardRef, currentElement } = useForwardExpose();
const hovered = ref(false),
pressed = ref(false),
focusVisible = ref(false);
let registered: TabsKey | undefined;
watch(
[currentElement, value],
([el, key]) => {
if (registered !== undefined) ctx.elements.delete(registered);
if (el) {
ctx.elements.set(key, el);
registered = key;
}
ctx.measure();
},
{ flush: "post" },
);
onMounted(ctx.measure);
onBeforeUnmount(() => {
if (registered !== undefined) ctx.elements.delete(registered);
ctx.measure();
});
// Reka owns pointer/key activation. Handle automatic focus here so a parent
// rejecting an update receives one request for a complete pointer/key gesture.
let pointerGesture = false,
keyboardGesture = false;
function pointerStart() {
pointerGesture = true;
}
function keyStart(event: KeyboardEvent) {
if (event.key === "Enter" || event.key === " ") keyboardGesture = true;
}
function click(event: MouseEvent) {
const handled = pointerGesture || keyboardGesture;
pointerGesture = false;
keyboardGesture = false;
if (disabled.value) event.preventDefault();
else if (!handled && !event.defaultPrevented) ctx.select(value.value);
}
function focus(event: FocusEvent) {
if (
ctx.keyboardActivation.value === "automatic" &&
!pointerGesture &&
!disabled.value
)
ctx.select(value.value);
focusVisible.value = (event.target as HTMLElement).matches(":focus-visible");
}
</script>
<template>
<TabsTrigger
:ref="forwardRef"
v-bind="$attrs"
:value="tabsWireKey(value)"
as-child
:as="as ?? (href ? 'a' : 'button')"
:href="disabled ? undefined : href"
:disabled="disabled"
:aria-disabled="disabled || undefined"
class="hv-tabs__tab"
data-slot="tabs-tab"
:data-selected="selected || undefined"
:data-disabled="disabled ? '' : undefined"
:data-hovered="(!disabled && hovered) || undefined"
:data-pressed="(!disabled && pressed) || undefined"
:data-focus-visible="focusVisible || undefined"
@mousedown="pointerStart"
@keydown="keyStart"
@pointerenter="hovered = true"
@pointerleave="
hovered = false;
pressed = false;
"
@pointerdown="pressed = true"
@pointerup="pressed = false"
@focus="focus"
@blur="
focusVisible = false;
pressed = false;
"
@click="click"
>
<component
:is="as ?? (href ? 'a' : 'button')"
:id="ctx.domId('tab', value)"
:data-disabled="disabled ? '' : undefined"
:aria-controls="
'aria-controls' in $attrs
? ($attrs['aria-controls'] as string)
: ctx.panels.value.has(value)
? ctx.domId('panel', value)
: undefined
"
>
<slot :is-selected="selected" :is-disabled="disabled" />
</component>
</TabsTrigger>
</template>
@@ -0,0 +1,44 @@
import { inject, type InjectionKey, type Ref, type ComputedRef } from "vue";
export type TabsKey = string | number;
export interface TabBox {
x: number;
y: number;
width: number;
height: number;
}
export interface TabsContext {
selected: ComputedRef<TabsKey | undefined>;
keyboardActivation: ComputedRef<"automatic" | "manual">;
select: (value: TabsKey) => void;
orientation: ComputedRef<"horizontal" | "vertical">;
variant: ComputedRef<"primary" | "secondary">;
dir: ComputedRef<"ltr" | "rtl">;
disabled: (key: TabsKey) => boolean;
domId: (kind: "tab" | "panel", key: TabsKey) => string;
panels: Ref<Set<TabsKey>>;
list: Ref<HTMLElement | undefined>;
elements: Map<TabsKey, HTMLElement>;
boxes: Ref<Map<TabsKey, TabBox>>;
ready: Ref<boolean>;
measure: () => void;
}
export const tabsKey: InjectionKey<TabsContext> = Symbol("hv-tabs");
export function useTabs() {
const ctx = inject(tabsKey);
if (!ctx) throw new Error("Tabs parts require Tabs.");
return ctx;
}
export const tabKey: InjectionKey<ComputedRef<TabsKey>> = Symbol("hv-tab");
export function useTabKey() {
const value = inject(tabKey);
if (!value) throw new Error("TabsIndicator requires TabsTab.");
return value;
}
// An empty string is reserved for no selection. Encode user keys so Reka is
// always controlled, even when an empty/disabled collection initially has no key.
export function tabsWireKey(key: TabsKey | undefined): string {
return key === undefined
? ""
: `${typeof key === "number" ? "n" : "s"}:${key}`;
}
+33
View File
@@ -466,3 +466,36 @@ export type { TooltipArrowProps } from "./types";
export { tooltipVariants, type TooltipVariants } from "@heroui-vue/styles";
export type { OverlayPlacement } from "./components/overlay/placement";
export { default as ScrollShadow } from "./components/scroll-shadow/ScrollShadow.vue";
export type { ScrollShadowVisibility } from "./components/scroll-shadow/types";
export {
scrollShadowVariants,
tabsVariants,
type ScrollShadowVariants,
type TabsVariants,
} from "@heroui-vue/styles";
export { default as Tabs } from "./components/tabs/Tabs";
export { default as TabsListContainer } from "./components/tabs/TabsListContainer.vue";
export { default as TabsList } from "./components/tabs/TabsList.vue";
export { default as TabsTab } from "./components/tabs/TabsTab.vue";
export { default as TabsPanel } from "./components/tabs/TabsPanel.vue";
export { default as TabsIndicator } from "./components/tabs/TabsIndicator.vue";
export { default as TabsSeparator } from "./components/tabs/TabsSeparator.vue";
export type { TabsKey } from "./components/tabs/context";
export {
useScrollShadow,
type UseScrollShadowProps,
} from "./components/scroll-shadow/useScrollShadow";
export type {
ScrollShadowProps,
TabsProps,
TabsListContainerProps,
TabsListProps,
TabsTabProps,
TabsPanelProps,
TabsIndicatorProps,
TabsSeparatorProps,
} from "./types";
+26
View File
@@ -348,3 +348,29 @@ export type TooltipContentProps = InstanceType<typeof TooltipContent>["$props"];
import type TooltipArrow from "./components/tooltip/TooltipArrow.vue";
export type TooltipArrowProps = InstanceType<typeof TooltipArrow>["$props"];
import type ScrollShadow from "./components/scroll-shadow/ScrollShadow.vue";
export type ScrollShadowProps = InstanceType<typeof ScrollShadow>["$props"];
import type Tabs from "./components/tabs/Tabs";
export type TabsProps = InstanceType<typeof Tabs>["$props"];
import type TabsListContainer from "./components/tabs/TabsListContainer.vue";
export type TabsListContainerProps = InstanceType<
typeof TabsListContainer
>["$props"];
import type TabsList from "./components/tabs/TabsList.vue";
export type TabsListProps = InstanceType<typeof TabsList>["$props"];
import type TabsTab from "./components/tabs/TabsTab.vue";
export type TabsTabProps = InstanceType<typeof TabsTab>["$props"];
import type TabsPanel from "./components/tabs/TabsPanel.vue";
export type TabsPanelProps = InstanceType<typeof TabsPanel>["$props"];
import type TabsIndicator from "./components/tabs/TabsIndicator.vue";
export type TabsIndicatorProps = InstanceType<typeof TabsIndicator>["$props"];
import type TabsSeparator from "./components/tabs/TabsSeparator.vue";
export type TabsSeparatorProps = InstanceType<typeof TabsSeparator>["$props"];
+3 -1
View File
@@ -13,6 +13,8 @@ export default defineConfig({
],
build: {
lib: { entry: "src/index.ts", formats: ["es"], fileName: "index" },
rollupOptions: { external: ["vue", "reka-ui", "@heroui-vue/styles"] },
rollupOptions: {
external: ["vue", "reka-ui", "@heroui-vue/styles", "@vueuse/core"],
},
},
});
+3
View File
@@ -113,6 +113,9 @@ importers:
'@heroui-vue/styles':
specifier: workspace:*
version: link:../styles
'@vueuse/core':
specifier: 14.4.0
version: 14.4.0(vue@3.5.44(typescript@5.9.3))
reka-ui:
specifier: ^2.11.0
version: 2.11.0(vue@3.5.44(typescript@5.9.3))
+28
View File
@@ -0,0 +1,28 @@
<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>
+355
View File
@@ -0,0 +1,355 @@
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { mount, flushPromises } from "@vue/test-utils";
import { defineComponent, nextTick, ref, type Component } from "vue";
import * as library from "../packages/vue/src";
import ScrollShadow from "../packages/vue/src/components/scroll-shadow/ScrollShadow.vue";
import BasicTabs from "../apps/docs/demos/tabs-basic.vue";
import { readFileSync } from "node:fs";
const wrappers: ReturnType<typeof mount>[] = [];
beforeEach(() => {
vi.stubGlobal(
"ResizeObserver",
class {
observe() {}
unobserve() {}
disconnect() {}
},
);
});
afterEach(async () => {
wrappers.splice(0).forEach((w) => w.unmount());
await flushPromises();
vi.unstubAllGlobals();
document.body.innerHTML = "";
vi.restoreAllMocks();
});
function attach(component: Component) {
const w = mount(component, { attachTo: document.body });
wrappers.push(w);
return w;
}
function fixture(template: string, setup = () => ({})) {
return attach(
defineComponent({
components: {
Tabs: library.Tabs,
TabsList: library.TabsList,
TabsTab: library.TabsTab,
TabsPanel: library.TabsPanel,
TabsIndicator: library.TabsIndicator,
},
template,
setup,
}),
);
}
async function settle() {
await flushPromises();
await nextTick();
await new Promise((resolve) => setTimeout(resolve, 25));
await nextTick();
}
function metrics(el: Element, values: Record<string, number>) {
for (const [key, value] of Object.entries(values))
Object.defineProperty(el, key, {
configurable: true,
value,
writable: true,
});
}
it("detects vertical edges with offset/tolerance, does not repeat callbacks, and clears disabled state", async () => {
const w = attach(ScrollShadow);
metrics(w.element, { scrollHeight: 500, clientHeight: 100, scrollTop: 0 });
await w.trigger("scroll");
await settle();
expect(w.attributes("data-bottom-scroll")).toBe("true");
expect(w.emitted("visibilityChange")?.at(-1)).toEqual(["bottom"]);
await w.trigger("scroll");
await settle();
expect(w.emitted("visibilityChange")).toHaveLength(1);
metrics(w.element, { scrollTop: 100 });
await w.trigger("scroll");
await settle();
expect(w.attributes("data-top-bottom-scroll")).toBe("true");
metrics(w.element, { scrollTop: 399 });
await w.trigger("scroll");
await settle();
expect(w.attributes("data-top-scroll")).toBe("true");
expect(w.attributes("data-bottom-scroll")).toBeUndefined();
await w.setProps({ isEnabled: false });
await settle();
expect(w.attributes("data-top-scroll")).toBeUndefined();
expect(w.attributes("data-scroll-shadow-mode")).toBe("manual");
await w.setProps({ visibility: "both" });
expect(w.attributes("data-top-bottom-scroll")).toBe("true");
});
it("normalizes horizontal negative RTL scroll and updates when content changes", async () => {
const w = mount(ScrollShadow, {
props: { orientation: "horizontal", offset: 10 },
attrs: { dir: "rtl" },
attachTo: document.body,
});
wrappers.push(w);
metrics(w.element, { scrollWidth: 300, clientWidth: 100, scrollLeft: -10 });
await w.trigger("scroll");
await settle();
expect(w.attributes("data-right-scroll")).toBe("true");
metrics(w.element, { scrollLeft: -50 });
await w.trigger("scroll");
await settle();
expect(w.attributes("data-left-right-scroll")).toBe("true");
metrics(w.element, { scrollWidth: 100, scrollLeft: 0 });
w.element.appendChild(document.createTextNode("changed"));
await settle();
expect(w.emitted("visibilityChange")?.at(-1)).toEqual(["none"]);
expect(w.attributes("data-left-right-scroll")).toBeUndefined();
});
it("keeps controlled visibility and caller attrs/styles on the actual scroll element", async () => {
const w = mount(ScrollShadow, {
props: { visibility: "top", isEnabled: false, size: 80 },
attrs: {
class: "caller",
"aria-label": "region",
style: { "--scroll-shadow-size": "55px" },
},
attachTo: document.body,
});
wrappers.push(w);
await settle();
expect(w.attributes("data-top-scroll")).toBe("true");
expect(w.attributes("aria-label")).toBe("region");
expect(w.classes()).toContain("caller");
expect(
(w.element as HTMLElement).style.getPropertyValue("--scroll-shadow-size"),
).toBe("55px");
expect(w.emitted("visibilityChange")).toBeUndefined();
await w.setProps({ orientation: "horizontal", visibility: "both" });
expect(w.attributes("data-top-scroll")).toBeUndefined();
expect(w.attributes("data-left-right-scroll")).toBe("true");
});
it("selects the first enabled tab, keeps unique ARIA links, switches content, and avoids form submission", async () => {
const w = attach(BasicTabs);
await settle();
const tabs = w.findAll("[role=tab]");
expect(tabs[0].attributes("aria-selected")).toBe("true");
for (const tab of tabs) {
expect(tab.attributes("type")).toBe("button");
const controls = tab.attributes("aria-controls");
if (!controls) throw new Error("Missing panel control ID");
const panel = document.getElementById(controls);
expect(panel).not.toBeNull();
expect(panel?.getAttribute("aria-labelledby")).toBe(tab.attributes("id"));
}
await tabs[1].trigger("mousedown", { button: 0, ctrlKey: false });
await settle();
expect(tabs[1].attributes("aria-selected")).toBe("true");
expect(w.text()).toContain("跟踪指标");
expect(w.text()).not.toContain("查看项目概览");
const indicators = w.findAll("[data-slot=tabs-indicator]");
expect(
indicators.filter(
(el) => (el.element as HTMLElement).style.visibility === "visible",
),
).toHaveLength(1);
});
it("supports controlled rejection and default aliases with number/string identity", async () => {
const selected = ref<string | number>("1");
const changed = vi.fn();
const w = fixture(
'<Tabs :model-value="selected" @selection-change="changed"><TabsList aria-label="keys"><TabsTab :value="1">number<TabsIndicator /></TabsTab><TabsTab value="1">string<TabsIndicator /></TabsTab></TabsList><TabsPanel :value="1">N</TabsPanel><TabsPanel value="1">S</TabsPanel></Tabs>',
() => ({ selected, changed }),
);
await settle();
const tabs = w.findAll("[role=tab]");
expect(tabs[0].attributes("id")).not.toBe(tabs[1].attributes("id"));
await tabs[0].trigger("mousedown", { button: 0, ctrlKey: false });
await settle();
expect(changed).toHaveBeenCalledWith(1);
expect(tabs[1].attributes("aria-selected")).toBe("true");
selected.value = 1;
await settle();
expect(tabs[0].attributes("aria-selected")).toBe("true");
});
it("moves focus by arrow/Home/End, skips disabled tabs, and supports manual activation", async () => {
const w = fixture(
'<Tabs keyboard-activation="manual"><TabsList aria-label="navigation"><TabsTab value="a">A</TabsTab><TabsTab value="b" is-disabled>B</TabsTab><TabsTab value="c">C</TabsTab></TabsList><TabsPanel value="a">Alpha</TabsPanel><TabsPanel value="c">Charlie</TabsPanel></Tabs>',
);
await settle();
const tabs = w.findAll("[role=tab]");
(tabs[0].element as HTMLElement).focus();
await tabs[0].trigger("keydown", { key: "ArrowRight" });
await settle();
expect(document.activeElement).toBe(tabs[2].element);
expect(tabs[0].attributes("aria-selected")).toBe("true");
await tabs[2].trigger("keydown", { key: "Enter" });
await settle();
expect(tabs[2].attributes("aria-selected")).toBe("true");
await tabs[2].trigger("keydown", { key: "Home" });
await settle();
expect(document.activeElement).toBe(tabs[0].element);
});
it("isolates nested instances and reconciles dynamic removed/disabled selected members", async () => {
const show = ref(true),
disabled = ref(false);
const w = fixture(
'<Tabs default-value="b"><TabsList aria-label="outer"><TabsTab value="a">A</TabsTab><TabsTab v-if="show" value="b" :is-disabled="disabled">B</TabsTab></TabsList><TabsPanel value="a"><Tabs><TabsList aria-label="inner"><TabsTab value="x">X</TabsTab></TabsList><TabsPanel value="x">Inner</TabsPanel></Tabs></TabsPanel><TabsPanel v-if="show" value="b">Beta</TabsPanel></Tabs>',
() => ({ show, disabled }),
);
await settle();
expect(w.find("[data-selected]").text()).toBe("B");
disabled.value = true;
await settle();
expect(w.findAll("[aria-selected=true]")).toHaveLength(2);
disabled.value = false;
await settle();
expect(w.find("[aria-selected=true]").text()).toBe("A");
show.value = false;
await settle();
expect(w.text()).not.toContain("Beta");
expect(w.findAll("[aria-selected=true]")).toHaveLength(2);
});
it("does not select or navigate a disabled link tab", async () => {
const w = fixture(
'<Tabs><TabsList><TabsTab value="a">A</TabsTab><TabsTab value="b" href="/bad" is-disabled>B</TabsTab></TabsList></Tabs>',
);
await settle();
const link = w.find("a");
expect(link.attributes("href")).toBeUndefined();
expect(link.attributes("aria-disabled")).toBe("true");
await link.trigger("mousedown", { button: 0, ctrlKey: false });
await link.trigger("click");
expect(w.find("[aria-selected=true]").text()).toBe("A");
});
const demos = import.meta.glob(
"../apps/docs/demos/{scroll-shadow,tabs}-*.vue",
{ eager: true, import: "default" },
);
import Structure from "./fixtures/tabs-structure.vue";
it("matches all 7/10 fixed baseline previews and mounts every shared SFC without warnings", async () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {}),
error = vi.spyOn(console, "error").mockImplementation(() => {});
for (const [family, group, count] of [
["scroll-shadow", "utilities", 7],
["tabs", "navigation", 10],
] as const) {
const baseline = readFileSync(
`../heroui/apps/docs/content/docs/cn/react/components/(${group})/${family}.mdx`,
"utf8",
);
const current = readFileSync(`apps/docs/components/${family}.md`, "utf8");
const names = (s: string) =>
[
...s.matchAll(/<ComponentPreview\s+(?:isBgSolid\s+)?name="([^"]+)"/g),
].map((m) => m[1]);
expect(names(current)).toEqual(names(baseline));
expect(names(current)).toHaveLength(count);
for (const name of names(current)) {
const w = mount(demos[`../apps/docs/demos/${name}.vue`] as Component, {
attachTo: document.body,
});
await flushPromises();
w.unmount();
await flushPromises();
}
}
const w = mount(Structure, { attachTo: document.body });
await flushPromises();
w.unmount();
await flushPromises();
expect(warn.mock.calls).toEqual([]);
expect(error.mock.calls).toEqual([]);
});
it("hydrates initial IDs without mismatches and updates the actual linked panel", async () => {
const { createSSRApp } = await import("vue");
const { renderToString } = await import("@vue/server-renderer");
const html = await renderToString(createSSRApp(BasicTabs));
const root = document.createElement("div");
root.innerHTML = html;
document.body.appendChild(root);
const before = Array.from(root.querySelectorAll("[role=tab]")).map(
(el) => el.id,
);
const warn = vi.spyOn(console, "warn").mockImplementation(() => {}),
error = vi.spyOn(console, "error").mockImplementation(() => {});
const app = createSSRApp(BasicTabs);
app.mount(root);
await settle();
try {
expect(
Array.from(root.querySelectorAll("[role=tab]")).map((el) => el.id),
).toEqual(before);
expect(warn.mock.calls).toEqual([]);
expect(error.mock.calls).toEqual([]);
const last = root.querySelectorAll("[role=tab]")[2] as HTMLElement;
last.dispatchEvent(
new MouseEvent("mousedown", { bubbles: true, button: 0 }),
);
await settle();
expect(
document.getElementById(last.getAttribute("aria-controls")!)?.hidden,
).toBe(false);
} finally {
app.unmount();
}
});
it("preserves dynamic caller ARIA through the native slot boundary", async () => {
const controls = ref("external"),
label = ref("label-one");
const w = fixture(
'<Tabs><TabsList><TabsTab value="a" :aria-controls="controls">A</TabsTab></TabsList><TabsPanel value="a" :aria-labelledby="label">Content</TabsPanel></Tabs>',
() => ({ controls, label }),
);
await settle();
expect(w.get("[role=tab]").attributes("aria-controls")).toBe("external");
expect(w.get("[role=tabpanel]").attributes("aria-labelledby")).toBe(
"label-one",
);
controls.value = "changed";
label.value = "label-two";
await settle();
expect(w.get("[role=tab]").attributes("aria-controls")).toBe("changed");
expect(w.get("[role=tabpanel]").attributes("aria-labelledby")).toBe(
"label-two",
);
});
it("requests one controlled update per complete pointer gesture when the parent rejects it", async () => {
const change = vi.fn();
const w = fixture(
'<Tabs model-value="a" @selection-change="change"><TabsList><TabsTab value="a">A</TabsTab><TabsTab value="b">B</TabsTab></TabsList></Tabs>',
() => ({ change }),
);
await settle();
const second = w.findAll("[role=tab]")[1];
await second.trigger("mousedown", { button: 0, ctrlKey: false });
(second.element as HTMLElement).focus();
await second.trigger("mouseup");
await second.trigger("click");
await settle();
expect(change.mock.calls).toEqual([["b"]]);
expect(w.get("[aria-selected=true]").text()).toBe("A");
});
it("stays controlled after starting with an entirely disabled collection", async () => {
const selected = ref<string | undefined>(),
disabled = ref(["a", "b"]);
const change = vi.fn();
const w = fixture(
'<Tabs :model-value="selected" :disabled-keys="disabled" @selection-change="change"><TabsList><TabsTab value="a">A</TabsTab><TabsTab value="b">B</TabsTab></TabsList><TabsPanel value="a">Alpha</TabsPanel><TabsPanel value="b">Beta</TabsPanel></Tabs>',
() => ({ selected, disabled, change }),
);
await settle();
expect(w.find("[aria-selected=true]").exists()).toBe(false);
selected.value = "a";
disabled.value = [];
await settle();
await w
.findAll("[role=tab]")[1]
.trigger("mousedown", { button: 0, ctrlKey: false });
await settle();
expect(change).toHaveBeenCalledWith("b");
expect(w.get("[aria-selected=true]").text()).toBe("A");
expect(w.get("[data-selected]").text()).toBe("A");
});
+27
View File
@@ -432,3 +432,30 @@ it("renders public Modal Popover and Tooltip roots without browser globals", asy
expect(html).not.toContain('role="dialog"');
expect(html).not.toContain('role="tooltip"');
});
it("renders ScrollShadow and Tabs without browser globals and resolves initial panel IDs", async () => {
const { ScrollShadow, Tabs, TabsList, TabsTab, TabsPanel, TabsIndicator } =
await import("../packages/vue/src");
const html = await renderToString(
createSSRApp({
render: () =>
h(Tabs, {}, () => [
h(TabsList, { "aria-label": "SSR tabs" }, () => [
h(TabsTab, { value: "a" }, () => ["A", h(TabsIndicator)]),
h(TabsTab, { value: "b" }, () => ["B", h(TabsIndicator)]),
]),
h(TabsPanel, { value: "a" }, () =>
h(ScrollShadow, { visibility: "bottom" }, () => "SSR content"),
),
h(TabsPanel, { value: "b" }, () => "not selected"),
]),
}),
);
expect(html).toContain('aria-selected="true"');
expect(html).toContain('data-bottom-scroll="true"');
expect(html).toContain("SSR content");
expect(html).not.toContain("not selected");
const controls = html.match(/aria-controls="([^"]+)"/)?.[1];
expect(controls).toBeTruthy();
expect(html).toContain(`id="${controls}"`);
});
+52
View File
@@ -0,0 +1,52 @@
import { ref } from "vue";
import {
useScrollShadow,
type ScrollShadowProps,
type TabsProps,
type TabsTabProps,
type TabsPanelProps,
} from "../../packages/vue/src";
const shadow: ScrollShadowProps = {
orientation: "horizontal",
visibility: "both",
onVisibilityChange: (_value) => {},
};
const tabs: TabsProps = {
modelValue: 1,
keyboardActivation: "manual",
variant: "secondary",
disabledKeys: [1, "1"],
};
const tab: TabsTabProps = { value: "a", href: "/guide", isDisabled: true };
const panel: TabsPanelProps = { value: 1, shouldForceMount: true };
// @ts-expect-error variant is a fixed union
const badShadow: ScrollShadowProps = { variant: "shadow" };
// @ts-expect-error unsupported orientation
const badTabs: TabsProps = { orientation: "diagonal" };
// @ts-expect-error keys are not objects
const badTab: TabsTabProps = { value: { id: 1 } };
const badCallback: TabsProps = {
// @ts-expect-error controlled callback key remains string | number
"onUpdate:modelValue": (_value: boolean) => {},
};
function hookContract() {
const el = ref<HTMLElement>();
const state = useScrollShadow({
containerRef: el,
orientation: () => "horizontal",
});
// @ts-expect-error detection is readonly
state.visibility.value = "both";
return state;
}
void [
shadow,
tabs,
tab,
panel,
badShadow,
badTabs,
badTab,
badCallback,
hookContract,
];