fix: complete submenu panel ARIA, focus and event passthrough
- Submenu panel name priority is explicit aria-label > menu content channel > this instance's trigger; an explicit label drops the id reference so it cannot be shadowed. - openAutoFocus and animationend chain with the caller's handlers like keydown and interact-outside, so caller callbacks run and can cancel. - The panel loop falls back to the menu-level shouldFocusWrap and is always passed as a boolean: an undefined -> true update is dropped by the base prop chain, so the menu policy never applied. - Add a jsdom CSSOM polyfill for CSS.escape via vitest setupFiles; the animationend test no longer raises an unhandled error.
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
# B01 b474a63 复核
|
||||||
|
|
||||||
|
2026-10-24;feat/b01-menu-dropdown / b474a63。检查代码及本地复跑,不依赖交接中“全套通过”的表述。结论:原7项失败均修好;当前仍有原R9子面板透传的3个分支未完成,及1项测试环境异常,暂不合并。本轮未修改实现、未提交/推送。
|
||||||
|
|
||||||
|
## 通过部分
|
||||||
|
|
||||||
|
- 原整批20项探针全部通过,R4关闭策略、R6根事件合并、R8独立Menu名称及R9上一轮data/style/禁止Esc探针对应修复有效。
|
||||||
|
- 浏览器5181默认“复制链接”点击后menu数量0、trigger aria-expanded=false;没有复现默认不关闭回归。截图 `/private/tmp/b01-default-close-verified.png`。
|
||||||
|
- 包装组件真实Props消费与typecheck通过。
|
||||||
|
- 不要求为三级中间层焦点新增自动浏览器断言作为本轮门槛;现有浏览器序列观察和未自动化说明保留,不扩大SSR/水合/Nuxt范围。
|
||||||
|
|
||||||
|
## 剩余实现问题:均属原R9,不新增组件/能力范围
|
||||||
|
|
||||||
|
### 1. [P2] 子面板直接指定的ARIA被覆盖
|
||||||
|
|
||||||
|
DropdownSubmenuTrigger虽然先spread domProps,随后又无条件写 `aria-label: contentAttrs.label.value` / `aria-describedby: contentAttrs.describedBy.value`。子DropdownMenu没有指定这些值时为undefined,嵌套DropdownPopover传入的显式ARIA被删除。
|
||||||
|
|
||||||
|
回归:`openConfiguredSubmenu({'aria-label':'Direct submenu name','aria-describedby':'explicit-description'})`,实际aria-label=null。应同时保留Menu内容通道和面板调用方的明确属性,遵循约定优先级,并保证aria-labelledby不会意外压过显式名称;不要用undefined覆盖真实调用值。
|
||||||
|
|
||||||
|
### 2. [P2] 子面板openAutoFocus/animationend仍覆盖用户事件
|
||||||
|
|
||||||
|
SubContent的domProps中已有调用方onOpenAutoFocus,但后面重新赋值内部函数;onAnimationend也有同样覆盖结构。新增openAutoFocus回调探针调用次数为0(期望1)。根Popover已修的chain合并应等价应用于子面板,保留Vue事件数组与取消语义;不再只针对keydown单点修复。
|
||||||
|
|
||||||
|
### 3. [P2] 子菜单shouldFocusWrap没有传到底层
|
||||||
|
|
||||||
|
子DropdownMenu把shouldFocusWrap写进contentAttrs.loop;SubContent只收到panelProps.loop(即嵌套Popover显式loop),没有回退读取contentAttrs.loop,导致菜单级循环配置失效。此次b474a63修改时移除了原loop回退表达式。
|
||||||
|
|
||||||
|
新回归:子菜单shouldFocusWrap=true,焦点在First按ArrowUp,期望到Last,实际仍First。恢复明确优先级:面板显式loop→菜单shouldFocusWrap→底层默认;补双向边界及false不循环,别用声明支持代替行为。
|
||||||
|
|
||||||
|
以上3个分支均已加入 `tests/b01-complete-review.probe.test.ts`,现23项中原20项通过、新3项失败。请保持原断言,不删除或改成接受当前行为。
|
||||||
|
|
||||||
|
## 测试环境异常(与产品运行错误分开)
|
||||||
|
|
||||||
|
在既有 `root popover merges caller handlers for escape, outside, focus and animation` 用例派发animationend后,Reka Presence调用CSS.escape,而jsdom环境未提供CSS,抛未捕获TypeError。单独跑B01测试时65项断言通过但命令仍因1个Error失败;完整回归同样出现,不能称完全通过。
|
||||||
|
|
||||||
|
修复测试环境的CSS.escape能力/合成AnimationEvent夹具,保持测试可单独运行;不要关闭未捕获错误检查、吞Reka异常或为了测试修改产品行为。这不是新增SSR要求。
|
||||||
|
|
||||||
|
## 最终复跑记录
|
||||||
|
|
||||||
|
- `pnpm test`:72文件,71通过/1失败;931项,928通过/3失败,另1个未捕获Error(上述jsdom CSS.escape)。
|
||||||
|
- `pnpm typecheck`通过,`git diff --check`通过。
|
||||||
|
- 本次没有重做逐像素/读屏/物理触屏或新一轮tarball安装,不把它们描述为已验收。
|
||||||
|
|
||||||
|
返修范围仅上述3个子面板分支和测试夹具。修后跑整批23项、B01其他回归及完整测试,并确认无Unhandled Errors;保留已完成的Portal/关闭/事件取消/名称/类型修复。不创建下一组件任务,不合main、不推送。
|
||||||
@@ -42,3 +42,7 @@
|
|||||||
- 不新增SSR/水合/Nuxt验收,不把未重做的完整读屏/触屏/逐像素当作通过。
|
- 不新增SSR/水合/Nuxt验收,不把未重做的完整读屏/触屏/逐像素当作通过。
|
||||||
|
|
||||||
修复后按原整批清单复验受影响的默认/显式关闭策略、根/子事件及参数、独立Menu名称,并保持层级/Portal/Modal已通过路径。继续当前任务分支,交回复核,不合main、不推送。
|
修复后按原整批清单复验受影响的默认/显式关闭策略、根/子事件及参数、独立Menu名称,并保持层级/Portal/Modal已通过路径。继续当前任务分支,交回复核,不合main、不推送。
|
||||||
|
|
||||||
|
## b474a63 后续复核
|
||||||
|
|
||||||
|
原7项已修复通过。当前仅原R9子面板ARIA/事件/loop分支及测试环境异常未完成,详见 [B01-b474a63-review.md](./B01-b474a63-review.md)。三级中间焦点未固化自动断言不作为新增门槛。
|
||||||
|
|||||||
@@ -118,3 +118,16 @@ default、with-icons、with-descriptions、with-disabled-items、with-sections
|
|||||||
| R8 | 独立 `Menu` 自持内容属性通道,名称/描述落到真正的 `role="menu"` 节点 | 探针「standalone Menu keeps its own accessible name」 |
|
| R8 | 独立 `Menu` 自持内容属性通道,名称/描述落到真正的 `role="menu"` 节点 | 探针「standalone Menu keeps its own accessible name」 |
|
||||||
|
|
||||||
回归:**72 文件 / 928 项**通过;typecheck、Prettier、`git diff --check` 通过;独立 tarball 消费重跑通过;浏览器复验默认动作关闭、三级子菜单逐层 Esc 与 Portal/Modal 既有路径。
|
回归:**72 文件 / 928 项**通过;typecheck、Prettier、`git diff --check` 通过;独立 tarball 消费重跑通过;浏览器复验默认动作关闭、三级子菜单逐层 Esc 与 Portal/Modal 既有路径。
|
||||||
|
|
||||||
|
## b474a63 复核返修(2026-10-24)
|
||||||
|
|
||||||
|
按 [b474a63 复核记录](B01-b474a63-review.md) 收口 R9 子面板透传的 3 个分支与测试环境异常,探针 **23/23**。
|
||||||
|
|
||||||
|
| 项 | 修复 | 证据 |
|
||||||
|
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
|
||||||
|
| 子面板 ARIA 被覆盖 | 名称优先级:面板显式 `aria-label` > Menu 内容通道 > 实例触发器 id;有 `aria-label` 时移除 `aria-labelledby`,避免 id 引用压过显式名称 | 探针「submenu keeps a directly supplied panel accessible name」 |
|
||||||
|
| 子面板 `openAutoFocus` 被覆盖 | 与 `onKeydown`/`onInteractOutside`/`onAnimationend` 一样改为「调用方 + 内部」数组链,调用方先执行并按 `defaultPrevented` 取消 | 探针「submenu preserves a caller's openAutoFocus callback」 |
|
||||||
|
| 子菜单 `shouldFocusWrap` 未生效 | 面板 `loop` 恢复回退到菜单级 `contentAttrs.loop`;并统一传布尔值——实测 `undefined → true` 的更新会被底座属性链丢弃,`false → true` 才生效 | 探针「submenu respects the menu's shouldFocusWrap navigation」 |
|
||||||
|
| 测试环境 `CSS.escape` 缺失 | 新增 `tests/setup/cssom.ts`,仅在缺失时补 `CSS.escape` 并注册到 `vitest.config.ts` 的 `setupFiles`;不关错误检查、不改产品行为 | 单跑与全量均无 Unhandled Errors |
|
||||||
|
|
||||||
|
回归:**72 文件 / 931 项**通过、无未捕获错误;typecheck、Prettier、`git diff --check` 通过。
|
||||||
|
|||||||
@@ -971,3 +971,13 @@ Button/PopoverTrigger/Link/ToggleButtonGroup 源码及几何复核后,移除
|
|||||||
- **R9 子菜单参数**:面板属性补齐 `data-*`/`style`/`id`/其他事件透传;`isKeyboardDismissDisabled` 生效(Esc 既不关子层也不关父层,新增回归),`shouldCloseOnInteractOutside` 接到子面板的 outside 链路。
|
- **R9 子菜单参数**:面板属性补齐 `data-*`/`style`/`id`/其他事件透传;`isKeyboardDismissDisabled` 生效(Esc 既不关子层也不关父层,新增回归),`shouldCloseOnInteractOutside` 接到子面板的 outside 链路。
|
||||||
- **R8 独立 Menu 名称**:独立路径自身提供内容属性通道,`aria-label`/`aria-labelledby`/`aria-describedby` 落在真正的 `role="menu"` 节点(回归 `Standalone actions` 通过),静态布局与无滚动锁保持不变。
|
- **R8 独立 Menu 名称**:独立路径自身提供内容属性通道,`aria-label`/`aria-labelledby`/`aria-describedby` 落在真正的 `role="menu"` 节点(回归 `Standalone actions` 通过),静态布局与无滚动锁保持不变。
|
||||||
- 回归:**72 文件 / 928 项**通过(含新增 4 项自有回归:根面板事件合并、调用方取消 Escape、子面板禁止 Esc、菜单策略优先于分组模式);typecheck、Prettier 通过;独立 tarball 消费重跑通过;浏览器复验默认动作关闭与三级子菜单逐层 Esc。
|
- 回归:**72 文件 / 928 项**通过(含新增 4 项自有回归:根面板事件合并、调用方取消 Escape、子面板禁止 Esc、菜单策略优先于分组模式);typecheck、Prettier 通过;独立 tarball 消费重跑通过;浏览器复验默认动作关闭与三级子菜单逐层 Esc。
|
||||||
|
|
||||||
|
### B01 b474a63 复核返修(同日)
|
||||||
|
|
||||||
|
按 [b474a63 复核记录](migrations/B01-b474a63-review.md) 处理 R9 子面板透传的 3 个分支与 1 项测试环境异常;探针 **23/23**。
|
||||||
|
|
||||||
|
- **子面板 ARIA**:名称优先级为「面板显式 `aria-label` → Menu 内容通道 → 本实例触发器 id」,显式名称存在时移除 `aria-labelledby`,不再被 id 引用压过。探针里 `Direct submenu name` 与 `explicit-description` 均保留。
|
||||||
|
- **子面板事件合并**:`onOpenAutoFocus`、`onAnimationend` 与 `onKeydown`、`onInteractOutside` 一样改为「调用方 + 内部」数组链,调用方先执行并按 `defaultPrevented` 取消;`openAutoFocus` 调用次数回归通过。
|
||||||
|
- **子菜单 `shouldFocusWrap`**:面板 `loop` 回退到菜单级配置,并统一传布尔值——实测底座属性链会丢弃 `undefined → true` 的更新(`false → true` 生效),因此不能传 `undefined`。双向首尾循环回归通过。
|
||||||
|
- **测试环境**:jsdom 缺少 `CSS`,Reka Presence 在 `animationend` 时会调用 `CSS.escape` 抛未捕获错误。新增 `tests/setup/cssom.ts` 仅在缺失时补齐该能力并注册到 `setupFiles`,未关闭错误检查、未吞异常、未改产品行为;单跑与全量都不再有 Unhandled Errors。
|
||||||
|
- 回归:**72 文件 / 931 项**通过(无未捕获错误);typecheck、Prettier、`git diff --check` 通过;未重做逐像素/读屏/物理触屏,仍按未验收记录。
|
||||||
|
|||||||
@@ -219,7 +219,9 @@ export default defineComponent({
|
|||||||
avoidCollisions: props.avoidCollisions ?? props.shouldFlip,
|
avoidCollisions: props.avoidCollisions ?? props.shouldFlip,
|
||||||
collisionPadding:
|
collisionPadding:
|
||||||
props.collisionPadding ?? props.containerPadding,
|
props.collisionPadding ?? props.containerPadding,
|
||||||
loop: props.loop ?? contentAttrs?.loop.value,
|
// Boolean on purpose: undefined -> true updates are dropped by
|
||||||
|
// the base prop chain.
|
||||||
|
loop: props.loop ?? contentAttrs?.loop.value ?? false,
|
||||||
onAnimationend: chain<AnimationEvent>(
|
onAnimationend: chain<AnimationEvent>(
|
||||||
"onAnimationend",
|
"onAnimationend",
|
||||||
onAnimationEnd,
|
onAnimationEnd,
|
||||||
|
|||||||
@@ -137,19 +137,28 @@ export default defineComponent({
|
|||||||
shouldCloseOutside?: (event: Event) => boolean;
|
shouldCloseOutside?: (event: Event) => boolean;
|
||||||
} = { dismissDisabled: false };
|
} = { dismissDisabled: false };
|
||||||
|
|
||||||
|
// Accessible-name decision for the current render; the repair pass reads it.
|
||||||
|
const panelAria: { label?: string; labelledBy?: string } = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reka labels the submenu surface with the id it generates for its own
|
* Reka labels the submenu surface with the id it generates for its own
|
||||||
* trigger, but our trigger item keeps an instance id, so that reference
|
* trigger, but our trigger item keeps an instance id, so that reference
|
||||||
* dangles. Point it at the real trigger element of this instance.
|
* dangles. Priority: explicit aria-label (wins over any id reference) >
|
||||||
|
* caller/Menu `aria-labelledby` > this instance's trigger element.
|
||||||
*/
|
*/
|
||||||
function repairLabel(explicit?: string) {
|
function repairLabel() {
|
||||||
const content = contentElement.value;
|
const content = contentElement.value;
|
||||||
const trigger = elementFromValue(triggerRef.value);
|
if (!content) return;
|
||||||
if (!content || !trigger) return;
|
if (panelAria.label) {
|
||||||
if (explicit) {
|
content.removeAttribute("aria-labelledby");
|
||||||
content.setAttribute("aria-labelledby", explicit);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (panelAria.labelledBy) {
|
||||||
|
content.setAttribute("aria-labelledby", panelAria.labelledBy);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const trigger = elementFromValue(triggerRef.value);
|
||||||
|
if (!trigger) return;
|
||||||
if (!trigger.id) trigger.id = fallbackId;
|
if (!trigger.id) trigger.id = fallbackId;
|
||||||
content.setAttribute("aria-labelledby", trigger.id);
|
content.setAttribute("aria-labelledby", trigger.id);
|
||||||
}
|
}
|
||||||
@@ -240,7 +249,12 @@ export default defineComponent({
|
|||||||
collisionPadding:
|
collisionPadding:
|
||||||
(popoverProps.collisionPadding as number | undefined) ??
|
(popoverProps.collisionPadding as number | undefined) ??
|
||||||
(popoverProps.containerPadding as number | undefined),
|
(popoverProps.containerPadding as number | undefined),
|
||||||
loop: popoverProps.loop as boolean | undefined,
|
// Always a boolean: an undefined -> true transition is dropped by the
|
||||||
|
// base prop chain, so the menu-level policy would never apply.
|
||||||
|
loop:
|
||||||
|
(popoverProps.loop as boolean | undefined) ??
|
||||||
|
contentAttrs.loop.value ??
|
||||||
|
false,
|
||||||
};
|
};
|
||||||
const side = (popoverProps.side as string | undefined) ?? position.side;
|
const side = (popoverProps.side as string | undefined) ?? position.side;
|
||||||
const align =
|
const align =
|
||||||
@@ -255,7 +269,40 @@ export default defineComponent({
|
|||||||
...asArray(popoverProps.onInteractOutside as Handler),
|
...asArray(popoverProps.onInteractOutside as Handler),
|
||||||
handleInteractOutside as (event: Event) => void,
|
handleInteractOutside as (event: Event) => void,
|
||||||
];
|
];
|
||||||
const labelledBy = contentAttrs.labelledBy.value;
|
const focusChain = [
|
||||||
|
...asArray(popoverProps.onOpenAutoFocus as Handler),
|
||||||
|
(event: Event) => {
|
||||||
|
if (event.defaultPrevented) return;
|
||||||
|
if (contentAttrs.autoFocus.value === false) event.preventDefault();
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const animationChain = [
|
||||||
|
...asArray(popoverProps.onAnimationend as Handler),
|
||||||
|
onAnimationEnd as (event: Event) => void,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Explicit caller values win over the Menu content channel; a label
|
||||||
|
// always beats an id reference so it cannot be shadowed silently.
|
||||||
|
const callerLabel = popoverProps["aria-label"] as string | undefined;
|
||||||
|
const callerLabelledBy = popoverProps["aria-labelledby"] as
|
||||||
|
string | undefined;
|
||||||
|
const callerDescribedBy = popoverProps["aria-describedby"] as
|
||||||
|
string | undefined;
|
||||||
|
const effectiveLabel = callerLabel ?? contentAttrs.label.value;
|
||||||
|
const effectiveLabelledBy =
|
||||||
|
callerLabelledBy ?? contentAttrs.labelledBy.value;
|
||||||
|
const describedBy = callerDescribedBy ?? contentAttrs.describedBy.value;
|
||||||
|
panelAria.label = effectiveLabel;
|
||||||
|
panelAria.labelledBy = effectiveLabelledBy;
|
||||||
|
const ariaProps: Record<string, unknown> = {};
|
||||||
|
if (effectiveLabel) {
|
||||||
|
ariaProps["aria-label"] = effectiveLabel;
|
||||||
|
// An id reference would win over the explicit label; drop it.
|
||||||
|
ariaProps["aria-labelledby"] = undefined;
|
||||||
|
} else if (effectiveLabelledBy) {
|
||||||
|
ariaProps["aria-labelledby"] = effectiveLabelledBy;
|
||||||
|
}
|
||||||
|
if (describedBy) ariaProps["aria-describedby"] = describedBy;
|
||||||
|
|
||||||
return h(
|
return h(
|
||||||
RekaDropdownMenuSub as never,
|
RekaDropdownMenuSub as never,
|
||||||
@@ -302,8 +349,7 @@ export default defineComponent({
|
|||||||
...panelProps,
|
...panelProps,
|
||||||
side,
|
side,
|
||||||
align,
|
align,
|
||||||
"aria-label": contentAttrs.label.value,
|
...ariaProps,
|
||||||
"aria-describedby": contentAttrs.describedBy.value,
|
|
||||||
class: [
|
class: [
|
||||||
dropdownCtx?.slots.value.popover(),
|
dropdownCtx?.slots.value.popover(),
|
||||||
popoverProps.class,
|
popoverProps.class,
|
||||||
@@ -314,21 +360,17 @@ export default defineComponent({
|
|||||||
"data-exiting": exiting.value || undefined,
|
"data-exiting": exiting.value || undefined,
|
||||||
onKeydown: keydownChain,
|
onKeydown: keydownChain,
|
||||||
onInteractOutside: interactChain,
|
onInteractOutside: interactChain,
|
||||||
onAnimationend: onAnimationEnd,
|
onAnimationend: animationChain,
|
||||||
onOpenAutoFocus: (event: Event) => {
|
onOpenAutoFocus: focusChain,
|
||||||
if (event.defaultPrevented) return;
|
|
||||||
if (contentAttrs.autoFocus.value === false)
|
|
||||||
event.preventDefault();
|
|
||||||
},
|
|
||||||
onVnodeMounted: (vnode) => {
|
onVnodeMounted: (vnode) => {
|
||||||
contentElement.value = menuSurfaceFromVNode(vnode);
|
contentElement.value = menuSurfaceFromVNode(vnode);
|
||||||
void nextTick(() => repairLabel(labelledBy));
|
void nextTick(repairLabel);
|
||||||
},
|
},
|
||||||
onVnodeUpdated: (vnode) => {
|
onVnodeUpdated: (vnode) => {
|
||||||
const element = menuSurfaceFromVNode(vnode);
|
const element = menuSurfaceFromVNode(vnode);
|
||||||
if (!element) return;
|
if (!element) return;
|
||||||
contentElement.value = element;
|
contentElement.value = element;
|
||||||
void nextTick(() => repairLabel(labelledBy));
|
void nextTick(repairLabel);
|
||||||
},
|
},
|
||||||
onVnodeUnmounted: () => {
|
onVnodeUnmounted: () => {
|
||||||
contentElement.value = null;
|
contentElement.value = null;
|
||||||
|
|||||||
@@ -341,3 +341,49 @@ it("standalone Menu keeps its own accessible name", async () => {
|
|||||||
document.querySelector('[role="menu"]')?.getAttribute("aria-label"),
|
document.querySelector('[role="menu"]')?.getAttribute("aria-label"),
|
||||||
).toBe("Standalone actions");
|
).toBe("Standalone actions");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("submenu keeps a directly supplied panel accessible name", async () => {
|
||||||
|
const panel = await openConfiguredSubmenu({
|
||||||
|
"aria-label": "Direct submenu name",
|
||||||
|
"aria-describedby": "explicit-description",
|
||||||
|
});
|
||||||
|
expect(panel.getAttribute("aria-label")).toBe("Direct submenu name");
|
||||||
|
expect(panel.getAttribute("aria-describedby")).toBe("explicit-description");
|
||||||
|
});
|
||||||
|
it("submenu preserves a caller's openAutoFocus callback", async () => {
|
||||||
|
const callback = vi.fn();
|
||||||
|
await openConfiguredSubmenu({ onOpenAutoFocus: callback });
|
||||||
|
expect(callback).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
it("submenu respects the menu's shouldFocusWrap navigation", async () => {
|
||||||
|
await render({}, () =>
|
||||||
|
h(DropdownSubmenuTrigger, {}, () => [
|
||||||
|
h(DropdownItem, { id: "sub" }, () => [
|
||||||
|
"Sub",
|
||||||
|
h(DropdownSubmenuIndicator),
|
||||||
|
]),
|
||||||
|
h(DropdownPopover, {}, () =>
|
||||||
|
h(DropdownMenu, { shouldFocusWrap: true }, () => [
|
||||||
|
h(DropdownItem, { id: "first", textValue: "First" }, () => "First"),
|
||||||
|
h(DropdownItem, { id: "last", textValue: "Last" }, () => "Last"),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
(document.querySelector('[data-key="sub"]') as HTMLElement).click();
|
||||||
|
await flushPromises();
|
||||||
|
const panel = document.querySelector("[data-submenu-content]")!;
|
||||||
|
const first = panel.querySelector('[data-key="first"]') as HTMLElement;
|
||||||
|
const last = panel.querySelector('[data-key="last"]') as HTMLElement;
|
||||||
|
first.focus();
|
||||||
|
await flushPromises();
|
||||||
|
first.dispatchEvent(
|
||||||
|
new KeyboardEvent("keydown", {
|
||||||
|
key: "ArrowUp",
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await flushPromises();
|
||||||
|
expect(document.activeElement).toBe(last);
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* jsdom lacks parts of the CSSOM. Reka's Presence uses `CSS.escape` when it
|
||||||
|
* resolves exiting children, so tests that dispatch real `animationend` events
|
||||||
|
* need the same capability a browser provides. Only fills the gap; never
|
||||||
|
* overrides an existing implementation.
|
||||||
|
*/
|
||||||
|
type CssEscapeHost = { escape?: (value: string) => string };
|
||||||
|
const cssGlobal = globalThis as unknown as { CSS?: CssEscapeHost };
|
||||||
|
|
||||||
|
if (!cssGlobal.CSS) cssGlobal.CSS = {};
|
||||||
|
|
||||||
|
if (typeof cssGlobal.CSS.escape !== "function") {
|
||||||
|
// Approximation of CSS.escape for selector fragments: hex-escape leading
|
||||||
|
// digits and any character outside the identifier set.
|
||||||
|
const escapeIdentifier = (value: string) => {
|
||||||
|
const input = String(value);
|
||||||
|
let output = "";
|
||||||
|
for (let index = 0; index < input.length; index += 1) {
|
||||||
|
const char = input[index];
|
||||||
|
const code = char.codePointAt(0) ?? 0;
|
||||||
|
const isFirst = index === 0;
|
||||||
|
const digits = code >= 0x30 && code <= 0x39;
|
||||||
|
const safe =
|
||||||
|
code >= 0x80 ||
|
||||||
|
code === 0x2d ||
|
||||||
|
code === 0x5f ||
|
||||||
|
(code >= 0x30 && code <= 0x39) ||
|
||||||
|
(code >= 0x41 && code <= 0x5a) ||
|
||||||
|
(code >= 0x61 && code <= 0x7a);
|
||||||
|
if (code === 0) output += "\uFFFD";
|
||||||
|
else if ((isFirst && digits) || !safe)
|
||||||
|
output += `\\${code.toString(16)} `;
|
||||||
|
else output += char;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
};
|
||||||
|
cssGlobal.CSS.escape = escapeIdentifier;
|
||||||
|
}
|
||||||
+5
-1
@@ -23,5 +23,9 @@ export default defineConfig({
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
test: { environment: "jsdom", include: ["tests/**/*.test.ts"] },
|
test: {
|
||||||
|
environment: "jsdom",
|
||||||
|
include: ["tests/**/*.test.ts"],
|
||||||
|
setupFiles: ["tests/setup/cssom.ts"],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user