docs(canvas): explain menu focus and toolbar update boundaries

This commit is contained in:
2026-11-12 16:24:09 +08:00
parent c34d0b7ce0
commit 97fefaa519
7 changed files with 14 additions and 0 deletions
+3
View File
@@ -21,11 +21,14 @@ export function BranchMenu({ request, close, choose }: { request: BranchRequest
if (!request) return;
const focus = document.activeElement as HTMLElement | null;
ref.current?.querySelector<HTMLButtonElement>("button[data-choice]")?.focus();
// outside 不阻止事件,关闭后原指针仍可交给被点击的画布/控件;这是非模态浮层,不提供焦点圈定。
const outside = (event: PointerEvent) => { if (!ref.current?.contains(event.target as Node)) close(); };
const escape = (event: KeyboardEvent) => { if (event.key === "Escape") { event.preventDefault(); event.stopPropagation(); close(); focus?.focus(); } };
window.addEventListener("pointerdown", outside); window.addEventListener("keydown", escape, true);
return () => { window.removeEventListener("pointerdown", outside); window.removeEventListener("keydown", escape, true); };
}, [request, close]);
// choose 不在本组件内调用 close;异步创建、异常报告和关闭时机由宿主回调负责。
// close 引用或 request 变化会重装监听并重新捕获焦点,不只在空→非空时执行。
// 无document时不创建Portal。菜单位置按预设宽高限制在视口边距内;上下键循环所有按钮(含关闭)。
// 减少动态效果偏好禁用位移/缩放动画;退出动画仍通过AnimatePresence管理。
if (typeof document === "undefined") return null;