iter(g86): 弹层外部点击监听改按需挂载
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { effect, h, signal } from '@ui-arch/frame';
|
||||
import type { Signal } from '@ui-arch/frame';
|
||||
import { pushOverlay } from './overlay.js';
|
||||
import { bindOutside, pushOverlay } from './overlay.js';
|
||||
import { flip } from './position.js';
|
||||
import type { AutoCompleteOption, AutoCompleteProps } from './types.js';
|
||||
|
||||
@@ -102,10 +102,7 @@ export function autoComplete(props: AutoCompleteProps): HTMLElement {
|
||||
if (e.key === 'Tab') { open(false); return; } // 失焦前收起,避免残留浮层
|
||||
});
|
||||
|
||||
document.addEventListener('click', (e) => {
|
||||
if (root.contains(e.target as Node)) return; // 卫语句:组件内点击不处理
|
||||
open(false);
|
||||
});
|
||||
bindOutside(root, open, () => open(false)); // 点外部收起:仅展开期间挂监听,收起即摘
|
||||
effect(render); // 依赖 query / active / options,任一变化即重绘
|
||||
effect(() => {
|
||||
if (open()) releaseEsc ??= pushOverlay(() => { open(false); input.focus(); }); // 入栈逐层关闭
|
||||
|
||||
Reference in New Issue
Block a user