iter: d29 menu Home/End 跳转(与 select 键盘导航对称)

This commit is contained in:
HIsheR
2026-10-23 17:12:43 +08:00
parent c8154b4099
commit f8934ba84a
2 changed files with 4 additions and 2 deletions
+3 -1
View File
@@ -1,7 +1,7 @@
import { effect, h, signal } from '@ui-arch/frame';
import type { MenuItem, MenuProps } from './types.js';
/*** 下拉菜单:触发器 + 自绘弹层,项支持禁用 / 危险 / 分隔线;点项 / 点外部 / Esc 关闭,↑↓ 环形导航 ***/
/*** 下拉菜单:触发器 + 自绘弹层,项支持禁用 / 危险 / 分隔线;点项 / 点外部 / Esc 关闭,↑↓ 环形导航 + Home/End 跳转 ***/
export function menu(props: MenuProps): HTMLElement {
// —— 状态集中声明 ——
const open = signal(false); // 弹层开合
@@ -61,6 +61,8 @@ export function menu(props: MenuProps): HTMLElement {
trigger.focus(); // 收起后焦点回到触发器,键盘流不断
return;
}
if (e.key === 'Home' && open()) { e.preventDefault(); focusables[0]?.focus(); return; } // Home 跳首项
if (e.key === 'End' && open()) { e.preventDefault(); focusables[focusables.length - 1]?.focus(); return; } // End 跳末项
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return; // 卫语句:只接管上下键
e.preventDefault();
if (!open()) {