iter(g86): 弹层外部点击监听改按需挂载
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { effect, h, signal } from '@ui-arch/frame';
|
||||
import type { SelectProps } from './types.js';
|
||||
import { flip } from './position.js';
|
||||
import { pushOverlay } from './overlay.js';
|
||||
import { bindOutside, pushOverlay } from './overlay.js';
|
||||
|
||||
/*** 下拉选择:自绘弹层替代原生 select,value 信号双向绑定;searchable 时弹层顶部带搜索框,支持 ↑↓/Home/End 导航与 Esc 关闭 ***/
|
||||
export function select(props: SelectProps): HTMLElement {
|
||||
@@ -102,10 +102,7 @@ export function select(props: SelectProps): HTMLElement {
|
||||
if (e.key === 'End' && open()) { e.preventDefault(); options[list[list.length - 1]]?.focus(); return; } // End 跳末个可见项
|
||||
if (open() && !props.searchable && e.key.length === 1) jumpByTyped(e.key); // 可打印字符:键入快跳(搜索模式由输入框接管)
|
||||
});
|
||||
document.addEventListener('click', (e) => {
|
||||
if (root.contains(e.target as Node)) return; // 卫语句:组件内点击不处理
|
||||
open(false); // 点外部关闭
|
||||
});
|
||||
bindOutside(root, open, () => open(false)); // 点外部收起:仅展开期间挂监听,收起即摘
|
||||
effect(() => {
|
||||
const q = query();
|
||||
let shown = 0;
|
||||
|
||||
Reference in New Issue
Block a user