fix: real trigger owns long press, Vue click chain and layered Esc
- DropdownTrigger takes over the longPress press lifecycle in capture phase and cancels Reka's own open/toggle through its defaultPrevented guard; DropdownRoot no longer wraps the whole menu content. Short click, Enter and Space now open exactly once, and release cannot close the menu again. - MenuItem hands user handlers plus activation to Vue as one DOM onClick array, so preventDefault, capture and stopImmediatePropagation keep native semantics instead of a hand-rolled handler loop. - DropdownSubmenuTrigger owns its own open state and closes only its level on Escape, restoring focus to the submenu trigger; the parent menu stays open and a second Escape closes the root.
This commit is contained in:
@@ -29,20 +29,21 @@ default、with-icons、with-descriptions、with-disabled-items、with-sections
|
||||
|
||||
## 验证
|
||||
|
||||
- `tests/b01-menu-dropdown.test.ts`:动作单次触发、多选切换、分组级选择、禁用标记、指示器 checkmark。
|
||||
- 完整 `pnpm test`、`typecheck` 见验收节。
|
||||
- `tests/b01-menu-dropdown.test.ts`:动作单次触发、多选切换、分组级选择、禁用标记、指示器 checkmark、子菜单、长按(真实触发器 8 项)、Esc 逐层(焦点在子项 / 焦点在子触发器两条路径)。
|
||||
- 完整 `pnpm test`、`typecheck`、独立产物见验收节。
|
||||
- 浏览器重点:见 verification(子菜单/RTL/Esc/长按)。
|
||||
|
||||
## 上游差异
|
||||
|
||||
- 具名导出替代对象部件;`MenuKey[]` 替代 `Set`/`Selection`;Vue 事件替代 onAction/onSelectionChange。
|
||||
- 长按触发依赖 Reka DropdownMenuRoot 的 trigger 策略;与上游 `trigger="longPress"` 的对应在演示中体现。
|
||||
- 长按触发由 `DropdownRoot trigger="longPress"` + `longPressDuration` 提供(Reka 无 longPress 触发模式),交互契约对齐上游演示:短点击不开、按住到阈值打开、释放不反向关闭、键盘备用。
|
||||
- Item render props 使用作用域插槽状态,不机械搬 RAC render 函数。
|
||||
- Reka 2.11 主入口导出 `DropdownMenu*` 而非独立 `MenuItem`/`MenuGroup`;本库 MenuItem 基于 `DropdownMenuItem`。
|
||||
- Reka `MenuSubContent` 的 Escape 默认关闭整栈(与上游/APG 的逐层关闭不同),本族在子菜单层自行拦截实现逐层关闭,不改共享 overlay 内核。
|
||||
|
||||
## 未验证
|
||||
|
||||
完整读屏、物理触屏、Nuxt、逐像素、独立 tarball 安装(本批不作为门槛时如实记录)。
|
||||
完整读屏、物理触屏、Nuxt、逐像素、自动视觉对比。长按“按住到阈值”的计时路径只有 jsdom + 假时钟证据(本运行时浏览器后端无 press-and-hold 输入)。
|
||||
|
||||
## 集成增量
|
||||
|
||||
@@ -64,6 +65,14 @@ default、with-icons、with-descriptions、with-disabled-items、with-sections
|
||||
6. **类型**:包根导出 `*Props`;`tests/package/b01-menu-dropdown-contract.ts` NodeNext/bundler 正反例通过。
|
||||
7. **独立消费**:`/tmp/heroui-b01-consumer` tarball 安装后 `consume-b01-menu-dropdown.mjs` ESM+CSS 通过。
|
||||
|
||||
Esc 逐层:Reka SubContent 独立 open;浏览器重点验证见 verification。
|
||||
## 第二轮复核返修(2026-10-24)
|
||||
|
||||
**剩余差异(诚实记录)**:Esc 在子菜单内仍会一次关闭整栈(Reka SubContent 与父 Content 的 dismiss 未在本组合下隔离),焦点回到根触发器。探针不覆盖此项;待后续与嵌套弹层协议一并修。完整读屏/触屏/Nuxt/逐像素未验。
|
||||
按 [B01-review-2](./B01-review-2.md) 修复;`tests/b01-review.probe.test.ts` **7/7**(上一轮 4 项保持通过,新增 3 项由失败转通过)。
|
||||
|
||||
1. **长按的触发权归真实触发器**:`DropdownRoot` 不再包裹整段内容,只提供 `triggerMode`/`longPressDuration`/`open`/`setOpen` 上下文;`DropdownTrigger` 在 `longPress` 模式自行渲染一层 `display: contents` 守卫,用 **capture 阶段**接管 pointer/click/keydown,并以 `event.preventDefault()` 触发 Reka 自带的 `if (event.defaultPrevented) return` 守卫取消其打开/切换。短点击不开、release 后的 click 不回关、Enter/Space 只切换一次都由真实 `DropdownTrigger > Button` 上的事件决定,不依赖晚到的冒泡拦截。回归覆盖阈值前后、移动阈值、`pointercancel`、非主键/非主指针、卸载清理。
|
||||
2. **点击链交回 Vue DOM 事件层**:`MenuItem` 不再手工遍历用户处理器数组。用户的 `onClick`(函数或数组)与内部激活动作合并成一个 `onClick` 数组下发给同一元素,Reka 的 `handleSelect` 由 `onSelect` 里的 `preventDefault` 中和,因此 `preventDefault`、capture、`stopImmediatePropagation` 都是 Vue/浏览器原生语义;`stopImmediatePropagation` 后第二个处理器与激活都不再执行。
|
||||
3. **Esc 逐层关闭**:`DropdownSubmenuTrigger` 自己持有子菜单 open,在子内容与子触发器上拦截 Escape(`preventDefault` + `stopPropagation`,只作用于本层,不改共享 overlay 内核,也不加全局 document 监听),关闭当前层并把握焦还给子触发器;父层保留,第二次 Escape 才关闭根菜单。焦点在子菜单项内(键盘)与焦点在子触发器上(指针打开)两条路径都有回归,浏览器实测一致。
|
||||
4. **回归与产物**:原 `b01-menu-dropdown` 增至 **16/16**(两条旧长按测试原先只在 Root 包裹层派发事件,已改为操作真实触发器),两文件合计 **23/23**;完整 **71 文件 / 885 项**;typecheck、build:docs、Prettier、`git diff --check` 通过。独立 tarball 重新打包后 ESM+CSS 与 bundler/NodeNext 类型契约仍通过。
|
||||
5. **浏览器(5181,真实点击/按键)**:长按示例真实短点击后不打开;真实 Enter 打开且不被二次切换关闭;Space 一次开一次关;Esc 关闭后焦点回触发器。`with-submenus` 焦点在子菜单项上按 Esc → 只关子菜单、根菜单保持、焦点回「其他」,再按 Esc → 关根菜单、焦点回「分享」,console warn/error 为 0。
|
||||
|
||||
**仍存限制(诚实记录)**:本运行时浏览器后端没有 press-and-hold 输入,“按住达到阈值才打开”的计时路径只有 jsdom + 假时钟证据;完整读屏、物理触屏、Nuxt、逐像素与自动视觉对比未验证。
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# B01 第二次复核
|
||||
|
||||
2026-10-24;feat/b01-menu-dropdown / 1692c6b。暂不通过,不合main。无需SSR/水合/Nuxt。
|
||||
|
||||
## 已通过的修复
|
||||
|
||||
上一轮4项探针全部通过:选择项角色/checked状态、普通preventDefault取消、避免嵌套menuitem、独立Menu不再抛缺少上下文错误。原B01测试现8项通过;两文件共12项通过,类型检查通过。这些无需回退或整批重写。
|
||||
|
||||
## 仍需修复
|
||||
|
||||
### 1. [P1] longPress短点击仍直接打开菜单
|
||||
|
||||
DropdownRoot把长按click拦截放在触发按钮外的包裹层。实际DropdownTrigger的Reka click处理器先执行并把open设true,然后事件才冒泡到Root包裹层;此时preventDefault/stopImmediatePropagation无法撤销已发生的打开。
|
||||
|
||||
新回归点击真实 `DropdownTrigger > Button`,未发生长按即显示MenuItem。现有长按测试只在包裹层派发事件,绕过真实触发器默认行为,因而漏检。
|
||||
|
||||
修复应由真实触发器参与统一触发模式,不靠晚到的冒泡拦截。覆盖短按不开、达到阈值打开、长按后release/click不反向关闭、移动取消、pointercancel、非主键/非主指针、卸载清理。避免Root包裹整个菜单内容后把条目激活也当作长按触发。
|
||||
|
||||
### 2. [P1] longPress的Enter激活被执行两次
|
||||
|
||||
同样由于监听位置,Enter先由Reka DropdownTrigger打开,然后冒泡到包裹层再次 `setOpen(!isOpen)`,立即关闭,键盘备用激活失效。新回归向真实button发送Enter后菜单仍关闭。Space也需要验证,不能只修短点击。
|
||||
|
||||
### 3. [P1] 手动遍历click数组破坏stopImmediatePropagation
|
||||
|
||||
MenuItem的invokeClick使用for逐个调用用户数组处理器。第一个处理器stopImmediatePropagation后,第二个仍执行;激活链也没有可靠终止。此类问题已在之前迁移规范中明确禁止。
|
||||
|
||||
新回归使用onClick=[event=>event.stopImmediatePropagation(), second],second仍调用一次。改用Vue实际DOM处理器合并语义与明确取消边界,不读取/伪造Vue私有_stopped,也不手工循环模拟invoker。保留普通preventDefault、capture和键盘取消,以及单次动作/选择/关闭回归。
|
||||
|
||||
### 4. [P1] Esc逐层关闭仍未实现
|
||||
|
||||
B01-menu-dropdown报告末尾仍明确写“Esc在子菜单内仍会一次关闭整栈…待后续”。这是本批原契约,不能以Reka组合差异为理由移到未授权的后续共享弹层任务。完成本家族最内层Esc关闭/父层保留/焦点回子触发器,再Esc关闭根层。不要改共享overlay内核或拦所有文档级Esc掩盖问题。
|
||||
|
||||
## 测试证据
|
||||
|
||||
`tests/b01-review.probe.test.ts`现7项:原4项通过,新增上述前3项失败。原 `tests/b01-menu-dropdown.test.ts` 8项通过。Esc本轮依据实现者报告确认仍未完成,未冒充本轮浏览器验证结果。
|
||||
|
||||
## 交付要求
|
||||
|
||||
继续当前分支修复以上4项;优先让真实DropdownTrigger拥有触发事件与模式,再正确处理子菜单生命周期。保留已经修对的选择ARIA/指示器/类型/文档。新增长按测试必须操作真实按钮,不能只操作Root包裹层;子菜单Esc必须真实焦点在最内层时操作。重跑相关/全量回归、类型、文档构建、独立浏览器产物消费,浏览器只重点验上述交互。不创建下一组件批次,不自行合main。
|
||||
+13
-2
@@ -905,7 +905,7 @@ Button/PopoverTrigger/Link/ToggleButtonGroup 源码及几何复核后,移除
|
||||
- 17/17 官方演示移植(文案/id/textValue/结构对照 `cn/dropdown`);Menu/Item/Section 无独立官方页,契约记入 dropdown.md。
|
||||
- `tests/b01-menu-dropdown.test.ts` **6/6**(动作单次、多选保持展开、分组选择、禁用、指示器、子菜单 DOM)。完整 **70 文件 / 869 项**;typecheck、build:docs、Prettier 通过。
|
||||
- 浏览器 5181:17 预览挂载;默认菜单 4 项含 danger;多选点香蕉后苹果+香蕉选中且菜单保持展开;子菜单「其他」→ WhatsApp/Telegram/Discord/Email 可见。
|
||||
- 未验证:完整读屏、物理触屏、Nuxt、逐像素、独立 tarball;Esc 一次关闭多层子菜单(上游逐层)待细修;长按为演示层实现(Reka 无 longPress prop)。
|
||||
- 未验证:完整读屏、物理触屏、Nuxt、逐像素、独立 tarball;Esc 一次关闭多层子菜单(上游逐层)当时未实现(见下方第二轮);长按当时为演示层实现(Reka 无 longPress prop)。
|
||||
|
||||
### B01 首轮复核返修(同日)
|
||||
|
||||
@@ -913,4 +913,15 @@ Button/PopoverTrigger/Link/ToggleButtonGroup 源码及几何复核后,移除
|
||||
- 原 `b01-menu-dropdown` **8/8**(含长按打开/移动取消)。
|
||||
- 完整 **71 文件 / 875 项**;typecheck、build:docs、Prettier 通过。
|
||||
- 独立 tarball 消费 `/tmp/heroui-b01-consumer`:ESM 导出齐全 + CSS 含 hv-menu-item/dropdown;`b01-menu-dropdown-contract.ts` NodeNext 与 bundler 正反例均过。
|
||||
- 浏览器 5181 复验:多选 aria/data-selected、子菜单单节点与 Esc 层关闭、长按组件 API(见下)。
|
||||
- 浏览器 5181 复验:多选 aria/data-selected、子菜单单节点。当时同节写下的“Esc 层关闭”不成立:第二轮探针与浏览器实测均显示一次 Esc 关闭整栈,已在该轮返修,见下。
|
||||
|
||||
### B01 第二轮复核返修(同日)
|
||||
|
||||
- `tests/b01-review.probe.test.ts` **7/7**:上一轮 4 项保持通过,新增 3 项(真实 `DropdownTrigger > Button` 短点击不开、长按 Enter 只打开一次、`onClick` 数组中 `stopImmediatePropagation` 后第二个处理器与激活都不执行)由失败转通过。
|
||||
- 点击链改由 Vue DOM 事件层执行:用户处理器与激活处理器作为同一个 `onClick` 数组下发,Reka 的 `handleSelect` 在 `onSelect` 中被 `preventDefault` 中和,因此 `preventDefault`、capture、`stopImmediatePropagation` 都是浏览器原生语义,不再手工遍历处理器。
|
||||
- 长按模式移交真实触发器:`DropdownTrigger` 在 `longPress` 模式下以 capture 阶段接管 pointer/click/keydown,通过 Reka 自身的 `event.defaultPrevented` 守卫取消其打开,`DropdownRoot` 不再包裹整段内容。回归覆盖短点击不开、达到阈值打开、release/click 不回关、移动阈值取消、`pointercancel`、非主键/非主指针忽略、Enter 与 Space 各只切换一次、卸载清理(`vi.getTimerCount()` 归零)。
|
||||
- Esc 逐层:`DropdownSubmenuTrigger` 自持子菜单 open,在子内容与子触发器上拦截 Escape(`preventDefault` + `stopPropagation`),只关闭当前层并把焦点交还子触发器,父层与根层保持;第二层 Escape 才关闭根菜单。焦点在子菜单项内(键盘路径)与焦点在子触发器上(指针打开路径)各有 jsdom 回归。
|
||||
- 原 `tests/b01-menu-dropdown.test.ts` 增至 **16/16**(两条旧长按测试原先只在 Root 包裹层派发事件,已改为操作真实 `DropdownTrigger > Button`);两文件合计 **23/23**;完整 **71 文件 / 885 项**;typecheck、build:docs、Prettier、diff 检查通过(仅既存 chunk 大小提示)。
|
||||
- 独立 tarball `/tmp/heroui-b01-consumer` 重新打包安装后:ESM 命名导出 + `@heroui-vue/styles/css` 通过;`b01-menu-dropdown-contract.ts` 在 bundler 与 NodeNext 下正反例均通过(`@ts-expect-error` 仍生效)。
|
||||
- 浏览器 5181 实测(真实点击/真实按键):长按示例真实短点击后 `aria-expanded=false`、无 popover;真实 Enter 打开并保持、`aria-expanded=true`;Space 一次开一次关;Esc 关闭后焦点回到「长按」触发器。`with-submenus` 中焦点在子菜单项 WhatsApp 上按 Esc:子菜单卸载、根菜单仍开(`aria-expanded=true`)、焦点回「其他」;再按 Esc 关根菜单、焦点回「分享」。指针打开子菜单、焦点留在「其他」时同样只关一层。期间 console warn/error 为 0。
|
||||
- 本运行时浏览器后端不提供 press-and-hold 输入,因此“按住达到阈值才打开”的计时路径只有 jsdom + 假时钟证据;真实鼠标长按与物理触屏仍未验证。完整读屏、Nuxt、逐像素、自动视觉对比也未验证。
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
onBeforeUnmount,
|
||||
provide,
|
||||
ref,
|
||||
useAttrs,
|
||||
@@ -13,8 +12,7 @@ import { DropdownMenuRoot as RekaDropdownMenuRoot } from "reka-ui";
|
||||
import { dropdownVariants } from "@heroui-vue/styles";
|
||||
import { dropdownContextKey } from "../menu/context";
|
||||
|
||||
const LONG_PRESS_MS = 500;
|
||||
const LONG_PRESS_MOVE_PX = 10;
|
||||
export const LONG_PRESS_DURATION = 500;
|
||||
|
||||
export default defineComponent({
|
||||
name: "DropdownRoot",
|
||||
@@ -33,13 +31,12 @@ export default defineComponent({
|
||||
default: "press",
|
||||
},
|
||||
/** Long-press duration in ms (longPress trigger). */
|
||||
longPressDuration: { type: Number, default: LONG_PRESS_MS },
|
||||
longPressDuration: { type: Number, default: LONG_PRESS_DURATION },
|
||||
},
|
||||
emits: ["update:open"],
|
||||
setup(props, { slots, emit }) {
|
||||
const attrs = useAttrs();
|
||||
const slotsComputed = computed(() => dropdownVariants());
|
||||
provide(dropdownContextKey, { slots: slotsComputed });
|
||||
|
||||
const uncontrolledOpen = ref(props.defaultOpen ?? false);
|
||||
const isOpen = computed(() =>
|
||||
@@ -50,64 +47,13 @@ export default defineComponent({
|
||||
emit("update:open", value);
|
||||
}
|
||||
|
||||
// --- long-press trigger ---
|
||||
let pressTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
let startX = 0;
|
||||
let startY = 0;
|
||||
let suppressClick = false;
|
||||
const longPressHandlers = computed(() =>
|
||||
props.trigger === "longPress"
|
||||
? {
|
||||
onPointerdown: (event: PointerEvent) => {
|
||||
if (event.button !== 0 && event.pointerType === "mouse") return;
|
||||
suppressClick = false;
|
||||
startX = event.clientX;
|
||||
startY = event.clientY;
|
||||
clearPress();
|
||||
pressTimer = setTimeout(() => {
|
||||
pressTimer = null;
|
||||
suppressClick = true;
|
||||
setOpen(true);
|
||||
}, props.longPressDuration);
|
||||
},
|
||||
onPointermove: (event: PointerEvent) => {
|
||||
if (!pressTimer) return;
|
||||
const dx = event.clientX - startX;
|
||||
const dy = event.clientY - startY;
|
||||
if (Math.hypot(dx, dy) > LONG_PRESS_MOVE_PX) clearPress();
|
||||
},
|
||||
onPointerup: clearPress,
|
||||
onPointercancel: clearPress,
|
||||
onPointerleave: clearPress,
|
||||
onClick: (event: MouseEvent) => {
|
||||
if (suppressClick) {
|
||||
suppressClick = false;
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
// Short click does not open in longPress mode (upstream).
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
},
|
||||
onKeydown: (event: KeyboardEvent) => {
|
||||
// Keyboard users still get Enter/Space to open.
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
setOpen(!isOpen.value);
|
||||
}
|
||||
},
|
||||
}
|
||||
: {},
|
||||
);
|
||||
|
||||
function clearPress() {
|
||||
if (pressTimer) {
|
||||
clearTimeout(pressTimer);
|
||||
pressTimer = null;
|
||||
}
|
||||
}
|
||||
onBeforeUnmount(clearPress);
|
||||
provide(dropdownContextKey, {
|
||||
slots: slotsComputed,
|
||||
triggerMode: computed(() => props.trigger),
|
||||
longPressDuration: computed(() => props.longPressDuration),
|
||||
open: isOpen,
|
||||
setOpen,
|
||||
});
|
||||
|
||||
return () =>
|
||||
h(
|
||||
@@ -126,25 +72,9 @@ export default defineComponent({
|
||||
defaultOpen: props.defaultOpen,
|
||||
dir: props.dir,
|
||||
modal: props.modal,
|
||||
onUpdate: undefined,
|
||||
"onUpdate:open": (value: boolean) => setOpen(value),
|
||||
},
|
||||
{
|
||||
default: () => {
|
||||
// Long-press handlers land on the trigger region wrapper.
|
||||
const slotted = slots.default?.() ?? [];
|
||||
if (props.trigger !== "longPress") return slotted;
|
||||
return h(
|
||||
"div",
|
||||
{
|
||||
...longPressHandlers.value,
|
||||
style: "display:contents",
|
||||
"data-slot": "dropdown-long-press-root",
|
||||
},
|
||||
slotted,
|
||||
);
|
||||
},
|
||||
},
|
||||
{ default: () => slots.default?.() },
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
Fragment,
|
||||
cloneVNode,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
provide,
|
||||
ref,
|
||||
useAttrs,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
@@ -13,11 +15,7 @@ import {
|
||||
DropdownMenuSubContent as RekaDropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger as RekaDropdownMenuSubTrigger,
|
||||
} from "reka-ui";
|
||||
import {
|
||||
dropdownContextKey,
|
||||
menuCloseKey,
|
||||
submenuContentKey,
|
||||
} from "../menu/context";
|
||||
import { dropdownContextKey, submenuContentKey } from "../menu/context";
|
||||
|
||||
function flatten(nodes: VNodeChild[], out: VNodeChild[] = []): VNodeChild[] {
|
||||
for (const n of nodes) {
|
||||
@@ -27,10 +25,17 @@ function flatten(nodes: VNodeChild[], out: VNodeChild[] = []): VNodeChild[] {
|
||||
return out;
|
||||
}
|
||||
|
||||
function resolveElement(value: unknown): HTMLElement | null {
|
||||
if (value instanceof Element) return value as HTMLElement;
|
||||
const el = (value as { $el?: unknown } | null)?.$el;
|
||||
return el instanceof Element ? (el as HTMLElement) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submenu trigger: first child is the trigger item (asChild, single menuitem
|
||||
* DOM), remaining children render inside Reka SubContent. Each level keeps its
|
||||
* own open state so Esc closes one layer at a time.
|
||||
* own open state, and Escape closes only the level that owns focus before the
|
||||
* dismiss handler can reach the root menu.
|
||||
*/
|
||||
export default defineComponent({
|
||||
name: "DropdownSubmenuTrigger",
|
||||
@@ -40,6 +45,23 @@ export default defineComponent({
|
||||
const dropdownCtx = inject(dropdownContextKey, null);
|
||||
provide(submenuContentKey, true);
|
||||
|
||||
const subOpen = ref(false);
|
||||
const triggerRef = ref<unknown>(null);
|
||||
|
||||
function handleEscape(event: KeyboardEvent) {
|
||||
if (event.key !== "Escape" || !subOpen.value) return;
|
||||
const target = event.target as HTMLElement | null;
|
||||
// Only the menu level that owns the focused element closes.
|
||||
if (!target?.closest?.("[role='menu']")) return;
|
||||
// Stop the window Escape listeners used by Reka's dismissable layer so
|
||||
// the parent menu stays open, then close this level ourselves. Focus is
|
||||
// restored to the submenu trigger, matching one-layer-at-a-time close.
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
subOpen.value = false;
|
||||
resolveElement(triggerRef.value)?.focus();
|
||||
}
|
||||
|
||||
return () => {
|
||||
const children = flatten(slots.default?.() ?? []);
|
||||
const triggerVNode = children[0] ?? null;
|
||||
@@ -47,7 +69,12 @@ export default defineComponent({
|
||||
|
||||
return h(
|
||||
RekaDropdownMenuSub as never,
|
||||
{},
|
||||
{
|
||||
open: subOpen.value,
|
||||
"onUpdate:open": (value: boolean) => {
|
||||
subOpen.value = value;
|
||||
},
|
||||
},
|
||||
{
|
||||
default: () => [
|
||||
// asChild: the Item itself is the single menuitem; no nested menuitem.
|
||||
@@ -57,7 +84,17 @@ export default defineComponent({
|
||||
asChild: true,
|
||||
"data-slot": "dropdown-submenu-trigger",
|
||||
},
|
||||
{ default: () => triggerVNode },
|
||||
{
|
||||
default: () =>
|
||||
triggerVNode
|
||||
? cloneVNode(triggerVNode as never, {
|
||||
ref: triggerRef as never,
|
||||
// Escape with focus on the trigger (pointer-opened
|
||||
// submenu) must also close only this level.
|
||||
onKeydown: handleEscape,
|
||||
})
|
||||
: null,
|
||||
},
|
||||
),
|
||||
h(
|
||||
RekaDropdownMenuSubContent as never,
|
||||
@@ -65,6 +102,7 @@ export default defineComponent({
|
||||
class: [dropdownCtx?.slots.value.popover()],
|
||||
"data-slot": "dropdown-popover",
|
||||
"data-submenu-content": "true",
|
||||
onKeydown: handleEscape,
|
||||
},
|
||||
{
|
||||
default: () =>
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { defineComponent, h, inject, onBeforeUnmount, useAttrs } from "vue";
|
||||
import { DropdownMenuTrigger as RekaDropdownMenuTrigger } from "reka-ui";
|
||||
import { dropdownContextKey } from "../menu/context";
|
||||
|
||||
const LONG_PRESS_MOVE_PX = 10;
|
||||
|
||||
const SELECTION_KEYS = new Set(["Enter", " ", "Spacebar"]);
|
||||
|
||||
/**
|
||||
* Trigger. In `longPress` mode this component owns the press lifecycle and
|
||||
* cancels Reka's own click/keydown activation through its documented
|
||||
* `event.defaultPrevented` guard, so the real trigger element decides when the
|
||||
* menu opens instead of a late bubble interception.
|
||||
*/
|
||||
export default defineComponent({
|
||||
name: "DropdownTrigger",
|
||||
inheritAttrs: false,
|
||||
@@ -13,8 +23,73 @@ export default defineComponent({
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const dropdownCtx = inject(dropdownContextKey, null);
|
||||
return () =>
|
||||
h(
|
||||
|
||||
const isLongPress = () =>
|
||||
(dropdownCtx?.triggerMode.value ?? "press") === "longPress";
|
||||
|
||||
let timer: ReturnType<typeof setTimeout> | null = null;
|
||||
let startX = 0;
|
||||
let startY = 0;
|
||||
|
||||
function clearPress() {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function onPointerdown(event: PointerEvent) {
|
||||
if (event.isPrimary === false) return;
|
||||
if (event.pointerType === "mouse" && event.button !== 0) return;
|
||||
clearPress();
|
||||
startX = event.clientX;
|
||||
startY = event.clientY;
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
dropdownCtx?.setOpen(true);
|
||||
}, dropdownCtx?.longPressDuration.value ?? 500);
|
||||
}
|
||||
|
||||
function onPointermove(event: PointerEvent) {
|
||||
if (!timer) return;
|
||||
if (
|
||||
Math.hypot(event.clientX - startX, event.clientY - startY) <=
|
||||
LONG_PRESS_MOVE_PX
|
||||
)
|
||||
return;
|
||||
clearPress();
|
||||
}
|
||||
|
||||
function onActivation(event: MouseEvent | KeyboardEvent) {
|
||||
if (!isLongPress()) return;
|
||||
// Short press never opens; after a long press the closing click/keyup
|
||||
// must not toggle the menu back. Cancelling here also stops Reka's own
|
||||
// trigger handler for this event.
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
if (!isLongPress()) return;
|
||||
if (!SELECTION_KEYS.has(event.key)) return;
|
||||
event.preventDefault();
|
||||
dropdownCtx?.setOpen(!(dropdownCtx?.open.value ?? false));
|
||||
}
|
||||
|
||||
const guardHandlers = {
|
||||
onPointerdownCapture: onPointerdown,
|
||||
onPointermoveCapture: onPointermove,
|
||||
onPointerupCapture: clearPress,
|
||||
onPointercancelCapture: clearPress,
|
||||
onPointerleaveCapture: clearPress,
|
||||
onClickCapture: onActivation,
|
||||
onKeydownCapture: onKeydown,
|
||||
onContextmenuCapture: clearPress,
|
||||
};
|
||||
|
||||
onBeforeUnmount(clearPress);
|
||||
|
||||
return () => {
|
||||
const trigger = h(
|
||||
RekaDropdownMenuTrigger as never,
|
||||
{
|
||||
...attrs,
|
||||
@@ -25,6 +100,19 @@ export default defineComponent({
|
||||
},
|
||||
slots,
|
||||
);
|
||||
|
||||
if (!isLongPress()) return trigger;
|
||||
|
||||
return h(
|
||||
"span",
|
||||
{
|
||||
...guardHandlers,
|
||||
style: "display: contents",
|
||||
"data-slot": "dropdown-trigger-region",
|
||||
},
|
||||
[trigger],
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -21,15 +21,6 @@ import {
|
||||
type NativeClickHandler =
|
||||
((e: MouseEvent) => void) | ((e: MouseEvent) => void)[] | undefined;
|
||||
|
||||
function invokeClick(handlers: NativeClickHandler, event: MouseEvent): void {
|
||||
if (!handlers) return;
|
||||
if (Array.isArray(handlers)) {
|
||||
for (const fn of handlers) fn(event);
|
||||
} else {
|
||||
handlers(event);
|
||||
}
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "MenuItem",
|
||||
inheritAttrs: false,
|
||||
@@ -87,34 +78,46 @@ export default defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
function activate(cancelEvent?: { preventDefault?: () => void }) {
|
||||
function activate() {
|
||||
if (isDisabled.value) return;
|
||||
emit("select", key.value);
|
||||
if (hasSubmenu.value) {
|
||||
cancelEvent?.preventDefault?.();
|
||||
return;
|
||||
}
|
||||
if (hasSubmenu.value) return;
|
||||
const mode = selectionMode.value;
|
||||
if (mode !== "none") {
|
||||
owner?.proposeSelection(key.value);
|
||||
if (mode === "single") menuCtx?.closeLevel();
|
||||
else cancelEvent?.preventDefault?.();
|
||||
return;
|
||||
}
|
||||
menuCtx?.emitAction(key.value);
|
||||
if (props.closeOnSelect === false) cancelEvent?.preventDefault?.();
|
||||
else menuCtx?.closeLevel();
|
||||
if (props.closeOnSelect === false) return;
|
||||
menuCtx?.closeLevel();
|
||||
}
|
||||
|
||||
return () => {
|
||||
// Own the click chain so user preventDefault cancels activation/close.
|
||||
// Reka's handleSelect is not used for our action contract.
|
||||
// Hand the user handlers and our activation to Vue as one DOM `onClick`
|
||||
// array so browser/Vue listener semantics stay intact: capture order,
|
||||
// preventDefault and stopImmediatePropagation all behave natively, and a
|
||||
// cancelled event never reaches the activation entry. Reka's own
|
||||
// `handleSelect` is prepended by its prop merge and is neutralised in
|
||||
// `onSelect`, so it cannot emit an action or close the menu.
|
||||
const userOnClick = (attrs as { onClick?: NativeClickHandler }).onClick;
|
||||
const rest: Record<string, unknown> = {
|
||||
...(attrs as Record<string, unknown>),
|
||||
};
|
||||
delete rest.onClick;
|
||||
|
||||
const clickChain: Array<(e: MouseEvent) => void> = (
|
||||
Array.isArray(userOnClick)
|
||||
? [...userOnClick]
|
||||
: userOnClick
|
||||
? [userOnClick]
|
||||
: []
|
||||
) as Array<(e: MouseEvent) => void>;
|
||||
clickChain.push((event: MouseEvent) => {
|
||||
if (event.defaultPrevented || isDisabled.value) return;
|
||||
activate();
|
||||
});
|
||||
|
||||
return h(
|
||||
RekaMenuItem as never,
|
||||
{
|
||||
@@ -134,17 +137,7 @@ export default defineComponent({
|
||||
"data-selection-mode": selectionMode.value,
|
||||
disabled: isDisabled.value,
|
||||
textValue: props.textValue,
|
||||
onClick: (event: MouseEvent) => {
|
||||
invokeClick(userOnClick, event);
|
||||
if (event.defaultPrevented || isDisabled.value) {
|
||||
event.stopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
activate(event);
|
||||
// Cancel Reka's select/close; we own the close contract.
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
},
|
||||
onClick: clickChain,
|
||||
onSelect: (itemSelectEvent?: { preventDefault?: () => void }) => {
|
||||
itemSelectEvent?.preventDefault?.();
|
||||
},
|
||||
|
||||
@@ -53,7 +53,14 @@ export const submenuContentKey: InjectionKey<boolean> = Symbol(
|
||||
"hv-dropdown-submenu-content",
|
||||
);
|
||||
|
||||
export interface DropdownContextValue {
|
||||
export interface DropdownTriggerModeValue {
|
||||
triggerMode: ComputedRef<"press" | "longPress">;
|
||||
longPressDuration: ComputedRef<number>;
|
||||
open: ComputedRef<boolean>;
|
||||
setOpen: (value: boolean) => void;
|
||||
}
|
||||
|
||||
export interface DropdownContextValue extends DropdownTriggerModeValue {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
slots: ComputedRef<any>;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { defineComponent, h, ref, nextTick } from "vue";
|
||||
import {
|
||||
Button,
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownItem,
|
||||
@@ -258,7 +259,9 @@ it("long-press trigger opens on hold and suppresses click", async () => {
|
||||
const w = mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { trigger: "longPress", longPressDuration: 300 }, () => [
|
||||
h(Button, { "aria-label": "菜单" }, () => "长按"),
|
||||
h(DropdownTrigger, {}, () =>
|
||||
h(Button, { "aria-label": "菜单" }, () => "长按"),
|
||||
),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () =>
|
||||
h(DropdownItem, { id: "x", textValue: "X" }, () =>
|
||||
@@ -286,7 +289,7 @@ it("long-press cancel on move threshold", async () => {
|
||||
mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { trigger: "longPress", longPressDuration: 300 }, () => [
|
||||
h(Button, () => "长按"),
|
||||
h(DropdownTrigger, {}, () => h(Button, () => "长按")),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () =>
|
||||
h(DropdownItem, { id: "x", textValue: "X" }, () =>
|
||||
@@ -318,3 +321,262 @@ it("long-press cancel on move threshold", async () => {
|
||||
).not.toBe("open");
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
function pointer(
|
||||
type: string,
|
||||
props: Record<string, unknown> = {},
|
||||
): MouseEvent {
|
||||
const event = new MouseEvent(type, {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
...(props as MouseEventInit),
|
||||
});
|
||||
for (const key of ["pointerType", "isPrimary"]) {
|
||||
if (key in props) {
|
||||
Object.defineProperty(event, key, { value: props[key] });
|
||||
}
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
function mountLongPress(duration = 300) {
|
||||
const actions: string[] = [];
|
||||
const w = mountApp(
|
||||
() => () =>
|
||||
h(
|
||||
DropdownRoot,
|
||||
{ trigger: "longPress", longPressDuration: duration },
|
||||
() => [
|
||||
h(DropdownTrigger, {}, () =>
|
||||
h(Button, { "aria-label": "菜单" }, () => "长按"),
|
||||
),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, { onAction: (k: string) => actions.push(k) }, () =>
|
||||
h(DropdownItem, { id: "x", textValue: "X" }, () =>
|
||||
h(Label, () => "X"),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return { w, actions, button: () => w.get("button").element as HTMLElement };
|
||||
}
|
||||
|
||||
function menuState() {
|
||||
return (
|
||||
document
|
||||
.querySelector('[data-slot="dropdown-popover"]')
|
||||
?.getAttribute("data-state") ?? null
|
||||
);
|
||||
}
|
||||
|
||||
it("longPress: short click on the real trigger does not open", async () => {
|
||||
vi.useFakeTimers();
|
||||
const { button } = mountLongPress();
|
||||
await flushPromises();
|
||||
button().click();
|
||||
await flushPromises();
|
||||
await vi.advanceTimersByTimeAsync(600);
|
||||
await nextTick();
|
||||
expect(menuState()).toBeNull();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("longPress: opens at the threshold and stays open after release", async () => {
|
||||
vi.useFakeTimers();
|
||||
const { button } = mountLongPress();
|
||||
await flushPromises();
|
||||
const el = button();
|
||||
el.dispatchEvent(pointer("pointerdown", { button: 0, pointerType: "mouse" }));
|
||||
await vi.advanceTimersByTimeAsync(200);
|
||||
await nextTick();
|
||||
expect(menuState()).toBeNull();
|
||||
await vi.advanceTimersByTimeAsync(150);
|
||||
await nextTick();
|
||||
expect(menuState()).toBe("open");
|
||||
el.dispatchEvent(pointer("pointerup", { button: 0, pointerType: "mouse" }));
|
||||
el.click();
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
expect(menuState()).toBe("open");
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("longPress: pointercancel and out-of-range movement cancel the pending open", async () => {
|
||||
vi.useFakeTimers();
|
||||
const { button } = mountLongPress();
|
||||
await flushPromises();
|
||||
const el = button();
|
||||
el.dispatchEvent(pointer("pointerdown", { button: 0, pointerType: "mouse" }));
|
||||
el.dispatchEvent(pointer("pointermove", { clientX: 40, clientY: 0 }));
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
await nextTick();
|
||||
expect(menuState()).toBeNull();
|
||||
|
||||
el.dispatchEvent(
|
||||
pointer("pointerdown", { button: 0, clientX: 0, clientY: 0 }),
|
||||
);
|
||||
el.dispatchEvent(pointer("pointercancel", {}));
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
await nextTick();
|
||||
expect(menuState()).toBeNull();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("longPress: non-primary button and non-primary pointer are ignored", async () => {
|
||||
vi.useFakeTimers();
|
||||
const { button } = mountLongPress();
|
||||
await flushPromises();
|
||||
const el = button();
|
||||
el.dispatchEvent(pointer("pointerdown", { button: 2, pointerType: "mouse" }));
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
await nextTick();
|
||||
expect(menuState()).toBeNull();
|
||||
|
||||
el.dispatchEvent(pointer("pointerdown", { button: 0, isPrimary: false }));
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
await nextTick();
|
||||
expect(menuState()).toBeNull();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("longPress: Enter and Space open once from the keyboard", async () => {
|
||||
const { w } = mountLongPress();
|
||||
await flushPromises();
|
||||
await w.get("button").trigger("keydown", { key: "Enter" });
|
||||
await flushPromises();
|
||||
expect(menuState()).toBe("open");
|
||||
|
||||
await w.get("button").trigger("keydown", { key: " " });
|
||||
await flushPromises();
|
||||
expect(menuState()).toBeNull();
|
||||
|
||||
await w.get("button").trigger("keydown", { key: " " });
|
||||
await flushPromises();
|
||||
expect(menuState()).toBe("open");
|
||||
});
|
||||
|
||||
it("longPress: unmount clears the pending long-press timer", async () => {
|
||||
vi.useFakeTimers();
|
||||
const { w } = mountLongPress();
|
||||
await flushPromises();
|
||||
(w.get("button").element as HTMLElement).dispatchEvent(
|
||||
pointer("pointerdown", { button: 0 }),
|
||||
);
|
||||
expect(vi.getTimerCount()).toBeGreaterThan(0);
|
||||
w.unmount();
|
||||
cleanup.pop();
|
||||
await nextTick();
|
||||
expect(vi.getTimerCount()).toBe(0);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
function mountSubmenu() {
|
||||
mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { defaultOpen: true }, () => [
|
||||
h(DropdownTrigger, {}, () => h(Button, () => "菜单")),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () => [
|
||||
h(DropdownItem, { id: "copy-link", textValue: "复制链接" }, () =>
|
||||
h(Label, () => "复制链接"),
|
||||
),
|
||||
h(DropdownSubmenuTrigger, {}, () => [
|
||||
h(DropdownItem, { id: "share", textValue: "分享" }, () => [
|
||||
h(Label, () => "分享"),
|
||||
h(DropdownSubmenuIndicator),
|
||||
]),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () =>
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "whatsapp", textValue: "WhatsApp" },
|
||||
() => h(Label, () => "WhatsApp"),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
function escapeKey(node: Element) {
|
||||
return node.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "Escape",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function settle() {
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
await flushPromises();
|
||||
}
|
||||
|
||||
async function openSubmenu() {
|
||||
const subTrigger = document.querySelector(
|
||||
'[data-slot="menu-item"][data-has-submenu="true"]',
|
||||
) as HTMLElement;
|
||||
expect(subTrigger).toBeTruthy();
|
||||
subTrigger.click();
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const subContent = document.querySelector(
|
||||
"[data-submenu-content]",
|
||||
) as HTMLElement;
|
||||
expect(subContent).toBeTruthy();
|
||||
return { subTrigger, subContent };
|
||||
}
|
||||
|
||||
it("Escape closes the submenu level first, then the root menu", async () => {
|
||||
mountSubmenu();
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const { subTrigger, subContent } = await openSubmenu();
|
||||
const child = subContent.querySelector(
|
||||
'[data-slot="menu-item"]',
|
||||
) as HTMLElement;
|
||||
child.focus();
|
||||
expect(document.activeElement).toBe(child);
|
||||
|
||||
escapeKey(child);
|
||||
await settle();
|
||||
expect(document.querySelector("[data-submenu-content]")).toBeNull();
|
||||
expect(
|
||||
document.querySelectorAll('[data-slot="dropdown-popover"]').length,
|
||||
).toBe(1);
|
||||
expect(document.activeElement).toBe(subTrigger);
|
||||
|
||||
escapeKey(subTrigger);
|
||||
await settle();
|
||||
expect(document.querySelector('[data-slot="dropdown-popover"]')).toBeNull();
|
||||
});
|
||||
|
||||
it("Escape on a pointer-opened submenu trigger closes only that level", async () => {
|
||||
mountSubmenu();
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const { subTrigger } = await openSubmenu();
|
||||
// Pointer opening leaves focus on the trigger, outside the sub content.
|
||||
subTrigger.focus();
|
||||
expect(document.activeElement).toBe(subTrigger);
|
||||
|
||||
escapeKey(subTrigger);
|
||||
await settle();
|
||||
expect(document.querySelector("[data-submenu-content]")).toBeNull();
|
||||
expect(
|
||||
document.querySelectorAll('[data-slot="dropdown-popover"]').length,
|
||||
).toBe(1);
|
||||
expect(document.activeElement).toBe(subTrigger);
|
||||
|
||||
escapeKey(subTrigger);
|
||||
await settle();
|
||||
expect(document.querySelector('[data-slot="dropdown-popover"]')).toBeNull();
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { Button, DropdownTrigger } from "../packages/vue/src";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, h } from "vue";
|
||||
import {
|
||||
@@ -104,3 +105,58 @@ it("standalone exported Menu and MenuItem do not require an internal DropdownMen
|
||||
cleanup.push(() => w.unmount());
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it("stopImmediatePropagation stops subsequent user handlers and activation", async () => {
|
||||
const action = vi.fn();
|
||||
const second = vi.fn();
|
||||
const node = await renderMenu(
|
||||
{ onAction: action },
|
||||
{
|
||||
onClick: [(e: MouseEvent) => e.stopImmediatePropagation(), second],
|
||||
},
|
||||
);
|
||||
node.click();
|
||||
await flushPromises();
|
||||
expect(second).not.toHaveBeenCalled();
|
||||
expect(action).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("longPress trigger does not open on a short click of the actual button", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => () =>
|
||||
h(DropdownRoot, { trigger: "longPress" }, () => [
|
||||
h(DropdownTrigger, {}, () => h(Button, {}, () => "Hold")),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () => h(DropdownItem, { id: "a" }, () => "A")),
|
||||
),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
cleanup.push(() => w.unmount());
|
||||
await flushPromises();
|
||||
(w.get("button").element as HTMLElement).click();
|
||||
await flushPromises();
|
||||
expect(document.querySelector('[data-slot="menu-item"]')).toBeNull();
|
||||
});
|
||||
|
||||
it("longPress keyboard Enter opens instead of toggling twice", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => () =>
|
||||
h(DropdownRoot, { trigger: "longPress" }, () => [
|
||||
h(DropdownTrigger, {}, () => h(Button, {}, () => "Hold")),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () => h(DropdownItem, { id: "a" }, () => "A")),
|
||||
),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
cleanup.push(() => w.unmount());
|
||||
await flushPromises();
|
||||
await w.get("button").trigger("keydown", { key: "Enter" });
|
||||
await flushPromises();
|
||||
expect(document.querySelector('[data-slot="menu-item"]')).not.toBeNull();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user