iter(g86): 弹层外部点击监听改按需挂载
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { effect, h, signal } from '@ui-arch/frame';
|
||||
import type { MenuItem, MenuProps } from './types.js';
|
||||
import { flip } from './position.js';
|
||||
import { pushOverlay } from './overlay.js';
|
||||
import { bindOutside, pushOverlay } from './overlay.js';
|
||||
|
||||
/*** 下拉菜单:触发器 + 自绘弹层,项支持禁用 / 危险 / 分隔线;点项 / 点外部 / Esc 关闭,↑↓ 环形导航 + Home/End 跳转 + 键入快跳 ***/
|
||||
export function menu(props: MenuProps): HTMLElement {
|
||||
@@ -91,10 +91,7 @@ export function menu(props: MenuProps): HTMLElement {
|
||||
focusables[(at + step + focusables.length) % focusables.length]?.focus(); // 环形移动
|
||||
});
|
||||
|
||||
document.addEventListener('click', (e) => {
|
||||
if (root.contains(e.target as Node)) return; // 卫语句:组件内点击不处理
|
||||
open(false); // 点外部收起
|
||||
});
|
||||
bindOutside(root, open, () => open(false)); // 点外部收起:仅展开期间挂监听,收起即摘
|
||||
|
||||
effect(() => {
|
||||
if (open()) {
|
||||
|
||||
Reference in New Issue
Block a user