mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +08:00
Add right-click menu to issue and patch lists
This commit is contained in:
@@ -17,3 +17,26 @@ export function menuFocusIndex(
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export const menuItemSelector = '[role="menuitem"], [role="menuitemcheckbox"]';
|
||||
|
||||
// Whether `item` belongs to `menu` itself rather than to a nested submenu.
|
||||
export function isOwnMenuItem(menu: HTMLElement, item: Element): boolean {
|
||||
return item.parentElement?.closest('[role="menu"]') === menu;
|
||||
}
|
||||
|
||||
export function ownMenuItems(menu: HTMLElement | undefined): HTMLElement[] {
|
||||
if (!menu) return [];
|
||||
return Array.from(
|
||||
menu.querySelectorAll<HTMLElement>(menuItemSelector),
|
||||
).filter(item => isOwnMenuItem(menu, item));
|
||||
}
|
||||
|
||||
export function focusMenuItem(ev: KeyboardEvent, items: HTMLElement[]) {
|
||||
if (items.length === 0) return;
|
||||
const current = items.findIndex(el => el === document.activeElement);
|
||||
const next = menuFocusIndex(ev.key, current, items.length);
|
||||
if (next === undefined) return;
|
||||
ev.preventDefault();
|
||||
items[next].focus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user