Files
heroui-vue/docs/audit-groups/07-overlays.md
T

59 lines
15 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 07 overlays 组(alert-dialog、drawer、modal、popover、toast、tooltip)审计报告
上游基线:heroui/(ce90ea3,HeroUI 3.2.6);Vue:heroui-vue/。示例注册 key 双方逐一比对,6 组件 51 个示例名称与数量全部一致,无缺失/新增。以下为硬差异(已剔除 use client、受控 idiom、slot="close"→XxxClose、render→as、onPress→@click、data-placement→data-side、hv- 前缀等框架/底座适配)。
### alert-dialog
- [示例] alert-dialog-custom-styles:Vue 缺顶部渐变光线装饰条 `pointer-events-none absolute inset-x-8 top-0 h-px bg-linear-to-r from-transparent via-accent/35 to-transparent dark:via-accent/45`,上游 Dialog 内有两层装饰(h-24 渐变 + h-px 光线),Vue 只迁移了 h-24 那层(`heroui/apps/docs/src/demos/cn/alert-dialog/custom-styles.tsx` vs `heroui-vue/apps/docs/demos/alert-dialog-custom-styles.vue`)。可见视觉差异。
- [示例] alert-dialog-custom-animations:动画类参数等价——backdrop 400/200ms、container zoom-in-95 / slide-in-from-bottom-4、cubic-bezier(0.16,1,0.3,1)/(0.7,0,0.84,0)/(0.25,1,0.5,1)/(0.5,0,0.75,0) 逐字一致。差异在内容:① "流体滑入"描述 Vue 截断,缺"适合底部抽屉或 Toast。";② 图标上游 `gravity-ui:arrow-up-from-line`,Vue 用 Tabler `IconArrowUp`(modal 同场景映射为 `arrow-bar-up`,两处图标选择也不一致)。
- [示例] alert-dialog-sizes:说明文字截断——cover 分支缺"(移动端约 16px、桌面端约 40px)"和",适合需要最大宽度又保留对话框气质的关键确认";非 cover 分支缺",以适配不同信息量"(两文件 sizes.tsx / alert-dialog-sizes.vue)。
- [示例] alert-dialog-custom-portal:正文 3 段 → 2 段,整段缺第 3 段"若容器存在 transform 或 filter 等属性,请注意浏览器会为其创建新的包含块,从而影响定位与层级关系。";第 2 段缺",同时仍保持焦点管理与无障碍行为";第 1 段缺"实际项目中请替换为真实说明内容。"。
- [示例] alert-dialog-controlled:缺"传入即可在外部管理状态。"及",无需手写回调"等句(其余为 React.useState→ref 措辞适配,不计)。
- [样式] alert-dialog.css 唯一规则差异:Vue 缺 `.alert-dialog__header > .modal__icon { @apply mb-0 }`(`heroui/packages/styles/components/alert-dialog.css`)。但上游图标实际类为 `.alert-dialog__icon`(`heroui/packages/react/src/components/alert-dialog/alert-dialog.tsx:328` slots.icon),选择器指向 `.modal__icon` 永不命中,且 `.modal__icon`/`.alert-dialog__icon` 均无 margin——判定为上游从 modal.css 复制的残留规则,无视觉影响(简注)。
- [API] 无缺失(Vue 为超集:AlertDialogClose、state/open、as/asChild)。上游文档不一致(简注):AlertDialog.Backdrop 表列 `UNSTABLE_portalContainer`,Drawer.Backdrop 表未列同类项。
- [文档] "无障碍"上游 5 条(焦点陷阱/Tab 循环/屏幕阅读器/滚动锁定/必需操作),Vue 4 条且缺"滚动锁定""Tab 循环"描述;"相关组件"上游为 `<RelatedComponents>` 自动生成,Vue 为 2 条手写链接。
### drawer
- [动画] 进退场机制差异(本组重点):上游 `.drawer__dialog` 用 transition 驱动 `translate`(`transition: translate var(--drawer-enter-duration) var(--drawer-enter-ease)`,`[data-exiting="true"] .drawer__dialog` 覆盖 exit 时长/缓动),位移状态由 `.drawer__content--*` 包装层上的 `translate: ±100%` 切换;Vue 改为 `@keyframes hv-drawer-in/out-*` 直接动画 `translate`(`heroui-vue/packages/styles/components/drawer.css`,data-entering/exiting 落在 dialog 本身)。`--drawer-enter-duration/--drawer-exit-duration/--drawer-enter-ease/--drawer-exit-ease` 四变量及默认值(250ms/200ms/cubic-bezier(0.32,0.72,0,1))双方一致;backdrop 进 250ms/退 200ms 同缓动(上游 transition、Vue keyframes)。但打断行为不同:transition 从当前计算值平滑反向(快速开↔关无跳位),keyframes 每次从 `from` 起播——entering 中途关闭时面板会先跳到全开位(translate 0 0)再滑出,反之亦然(待核实:实际跳位观感,与 Reka Presence 节点复用叠加时)。
- [实现] 拖拽关闭参数完全对齐:DRAG_THRESHOLD 8px、DISMISS_FRACTION 0.3、VELOCITY_THRESHOLD 0.5px/ms、回弹 `transform 300ms cubic-bezier(0.32,0.72,0,1)`、仅 handle/header/footer 可发起、body/交互元素排除、inline `transform` 与动画 `translate` 复合、关闭保留 inline transform 延续拖拽位置(`drawer.tsx` useDrawerDrag vs `heroui-vue/.../drawer/useDrawerDrag.ts`)。Vue 额外守卫:pointer capture 容错、pointercancel/lostpointercapture 处理、受控拒绝关闭时回滚、reduced-motion 回弹不过渡(行为更严,非缺失)。残余差异:上游拖动激活时 `style.transition="none"` 可冻结 translate 过渡,Vue 的进入 keyframe 不受 transition:none 影响,打开后 250ms 内开始拖动时 keyframe 仍驱动 translate(待核实)。
- [示例] drawer-basic:正文差异——上游"这是一个基于 React Aria Modal 组件构建的抽屉。…通过流畅的 CSS 过渡呈现动画效果。",Vue 去掉"基于 React Aria Modal 组件构建的"并新增"可拖动标题或页脚区域关闭。"(拖拽双方均有实现,属文案内容差)。
- [示例] drawer-controlled:Vue 缺状态行包裹 `flex w-full items-center justify-between`(上游两处,`drawer/controlled.tsx`),并缺"传入即可在外部管理状态。"",无需手写回调"等句。
- [文档] 上游"不可关闭""可滚动内容"两示例的说明段(isDismissable={false} 同时阻止拖拽与外部点击;body 区域排除拖拽避免滚动冲突)Vue 未迁移;CSS 类清单"对话框变体"4 条逐条说明合并为 1 行;"无障碍"5 条 → 3 条。
- [样式] 除动画机制与 hv- 前缀外,尺寸、圆角(min(32px,var(--radius-2xl)))、85vh/85vw、w-80 sm:w-96、handle/body/footer 等规则逐条一致;touch-action(dialog `none`、body `pan-y`)双方实现相同。
### modal
- [动画/实现] Vue 新增 `@keyframes modal-retain`(from/to 均 `visibility: visible`)与 `.modal__dialog[data-exiting="true"]` 的 `animation-name: modal-retain; animation-duration/delay: inherit; animation-fill-mode: both` 规则(`heroui-vue/packages/styles/components/modal.css`):因 Reka Presence 监视 Content 节点本身、而上游 RAC 由带动画的 Container 保活 Dialog,用"中性动画"继承容器退出时长(含调用方 duration 工具类)对齐卸载时机。机制不同、目标等价;可见残差点:另加 `.modal__dialog[data-exiting="true"] { pointer-events: none !important }`,退出 ~100ms 内点击穿透,而上游退出中的 dialog 仍可点击(极小行为差)。
- [样式] Vue 另有 `.modal__trigger.button { display: inline-flex }`(上游 `.modal__trigger` 基础为 inline-block):Vue 触发器类直接落在 Button 本体需保住 flex,属适配补偿,视觉等价(简注)。
- [示例] modal-with-form:行为/内容差异——Vue 增加真实表单提交(form `:id`、`@submit.prevent="submit"`,"发送消息"按钮 `type="submit" :form="formId"`),并在弹窗外新增结果行 `<p role="status" class="mt-3 text-sm text-muted">已记录表单:{{ result }}</p>`(`heroui-vue/apps/docs/demos/modal-with-form.vue`);上游"发送消息"只是 `slot="close"` 关闭按钮,无提交与结果展示(`modal/with-form.tsx`)。其余示例内容全等(modal-custom-animations 的动画参数、文案与 alert-dialog 不同地是完全一致,仅图标 gravity arrow-up-from-line → tabler arrow-bar-up;modal-custom-styles 两层装饰条齐全——恰与 alert-dialog 缺失形成对照)。
- [API] 上游文档自身不一致(需指出):组件结构与示例使用 `Modal.Icon`/`Modal.Heading`,但 API 参考无二者的表格,CSS 类清单也缺 `.modal__icon`/`.modal__heading` 及尺寸修饰类(--xs…--full);Vue 以"Vue 补充部件"表补上 Heading/Icon/Close/CloseTrigger,CSS 类清单则照抄上游缺项。
- [文档] `heroui-vue/apps/docs/components/modal.md` "相关组件"含指向自身的 `[Modal 模态框](./modal)`(popover、tooltip 页同样自链),为整段复制错误;上游用 `<RelatedComponents>` 自动生成。ModalContainer 的 placement/scroll/size 默认值(auto/inside/md、含 full)双方一致。
### popover
- [样式] data-side/--reka 适配之外:Vue `.hv-popover__dialog` 多出 `max-height: inherit; overflow-y: auto; overscroll-behavior: contain`(`heroui-vue/packages/styles/components/popover.css`),上游 `.popover__dialog` 仅 `p-4 outline-none`、高度约束由 RAC 行内 max-height 给 `.popover`。高内容场景 Vue 在 dialog 内滚动(箭头保持可见),上游溢出行为不同——可见行为差异(有意补偿,`popover.css` 注释自述)。
- [样式] 箭头旋转:上游按 `[data-placement]` 对 `[data-slot="popover-overlay-arrow"]` 施加 rotate 180/-90/90deg(`heroui/packages/styles/components/popover.css`),Vue 无此规则,由 Reka PopoverArrow 自动定位旋转(`PopoverArrow.vue` + `OverlayArrowShape.ts`,SVG path `M0 0C5.48483 8 6.5 8 12 0Z`、12×12、fill var(--overlay) 与上游一致,默认箭头多 aria-hidden)。属适配;四方向箭头朝向/描边观感需实测(待核实)。
- [API] 上游 API 参考缺 `Popover.Heading` 表(源码已导出 PopoverHeading,`popover.tsx:194`);Vue 有(as/id/默认插槽)。placement 默认 bottom、offset 默认 8、shouldFlip 默认 true 双方文档与实现一致(`PopoverContent.vue` 另有 crossOffset 0、containerPadding 12)。
- [实现] `.hv-popover` 的 z-index 由上游 RAC 行内改为 CSS `var(--z-index-overlay)`(底座适配,简注);exiting `pointer-events: none` 双方意图一致(Vue 因 Reka 行内规则加 !important)。
- [示例] 6 个示例中文文案、class 字符串与 props(with-arrow `offset=10`、placement 四向、interactive 的 size/variant 切换)全等,无硬差异。
### toast
- [API] `toast.getQueue()`(返回底层 react-stately 队列实例)上游提供(`toast-queue.ts:412`),Vue 不提供——已在 `toast.md` "上游差异与 SSR" 声明,属真实 API 缺口。
- [API] `actionProps` 形状差异:上游为 ButtonProps(按钮内容用 `children`、事件 `onPress`);Vue 为 `ButtonProps & { label }`(内容用 `label`、事件 `onClick`)——已声明,但属框架映射之外的字段改名。
- [实现] 队列/计时逐项对齐(`heroui/.../toast/toast-queue.ts` vs `heroui-vue/.../toast/toast-queue.ts`):默认 timeout 4000、exitDuration 300、maxVisibleToasts 3(仅视觉、不删旧条)、isExpanded 不暂停、hotkey ["altKey","KeyT"]、hover/focusin/visibilitychange 暂停、update 省略 timeout 保持剩余计时且 0 保持打开、update 目标不存在时回退新增、promise 原地结算(仅仍存活且未被替换的条目更新、结算后才起 4000ms 倒计时)、clear 逐条退出并触发 onClose、onClose 至多一次。未发现计时语义差异。
- [示例] toast-variants:accent/success/warning 三个操作按钮的 actionProps,上游不传 variant(Button 默认 `primary`,`button.styles.ts` defaultVariants),Vue 固定传 `secondary`(`toast-variants.vue` show())→ 操作按钮外观不同(可见差异)。按钮本体变体/类(danger-soft、secondary、tertiary、text-success/text-warning)与文案一致。
- [示例] 布局结构差(toast-variants / toast-simple / toast-custom-indicator / toast-custom-queue):上游用 `flex h-full max-w-xl flex-col items-center justify-center` 外壳 + `flex w-full flex-wrap items-center justify-center gap-4` 内层(custom-queue 为 `flex justify-center gap-2` 逐按钮包裹、Provider 与按钮交替),Vue 简化为单层 flex-wrap(variants 用 gap-3、custom-indicator 外壳 `flex flex-col gap-3`、custom-queue 平铺后统一挂 3 个 Provider)。内容/队列参数(maxVisibleToasts 2/3/1、placement bottom/bottom start/bottom end)一致,demo 容器宽度与换行行为略有不同。
- [示例] toast-callbacks:历史条 `h-5 w-5` → `size-5`(等价)、Vue 加 `motion-reduce:animate-none`(增强);其余(timeout 3000/10000/0、关闭历史面板文案)一致。
- [文档] 无障碍章节双方侧重不同(上游:F6 地标导航、role=alertdialog 播报、计时暂停;Vue:role=alert/inert/aria-hidden 细节、Alt+T、不抢焦点)——行为描述差异,未发现实现矛盾;toast.css 逐字节一致(除格式化)。
### tooltip
- [API] 全表对齐:delay 默认 1500(`--tooltip-delay`)、closeDelay 默认 500(`--tooltip-close-delay`)、trigger "hover"|"focus"、isDisabled false、shouldSkipAnimation false、Content offset 3(带箭头 7)、placement "top"(`tooltip.mdx` vs `tooltip.md`)。CSS 变量延迟双方均实现(Vue `tooltip/context.ts` cssTime 读触发器计算样式,缺省 1500/500)。
- [实现] 快速切换/warmup 机制不同:上游靠 RAC 全局 warmup + `TooltipAnimationScope` 清 shouldSkipAnimation 保住换提示时的淡入淡出(`tooltip.tsx:35-53`);Vue 用 document 级 `tooltip.open` 事件 + justOpening/immediate/closeDelay 标记实现"旧提示立即关、被中断的退出不自关"(`Tooltip.ts`)。文档已声明"此处与 React Aria 的全局 warmup 调度不同",属已声明的机制差异。
- [样式] 与 popover 同构差异:上游按 data-placement 对 `[data-slot="overlay-arrow"]` rotate,Vue 由 Reka 旋转(SVG、stroke-border/40、fill var(--overlay) 一致);`max-w-xs … break-all`、radius min(32px,var(--radius-xl))、进入/退出动画数值一致;Vue 多 `z-index: var(--z-index-overlay)`(上游 RAC 行内)与 exiting `pointer-events:none !important`(等效补偿)。
- [示例] 6 个示例中文文案、class、props(delay=0、with-arrow offset=12、placement 四向、custom-trigger size=sm)全等。
- [文档] tooltip.md"相关组件"含自链 `[Tooltip 工具提示](./tooltip)`(同 modal、popover 页)。
## 本组小结(最严重 3-5 条)
1. **drawer 进退场机制**:transition(translate) → keyframes,时长/缓动/`--drawer-*` 变量一致,但动画中途打断(快速开关、拖动中)不再从当前位姿平滑续播,关键帧从 from 起播存在跳位风险;拖动激活时进入 keyframe 仍驱动 translate(drawer.css、useDrawerDrag.ts,需真机验证)。
2. **alert-dialog-custom-styles 缺顶部渐变光线装饰条**(`inset-x-8 h-px bg-linear-to-r via-accent/35`),自定义样式示例可见视觉差异(modal 同类示例装饰齐全)。
3. **toast-variants 操作按钮变体差**:accent/success/warning 的 actionProps 上游为按钮默认 primary,Vue 固定 secondary,示例按钮外观不同。
4. **popover__dialog 新增滚动规则**(max-height:inherit + overflow-y:auto + overscroll-contain),高内容时滚动容器与上游不同。
5. **API/示例内容缺口**:`toast.getQueue()` 缺失;modal-with-form 弹窗外新增"已记录表单"输出与真实提交;alert-dialog sizes/custom-portal/custom-animations 三处中文文案截断或段落缺失。