/** * Shared keyboard navigation for menu-like content (dropdown-menu, * context-menu, menubar). * * Menu items are *slotted light-DOM children* of the `*-content` host, so they * must be collected from the host (`el.querySelectorAll`), never from a node * inside the content's own shadow root (#322). Each item renders its focus * target (`[role^="menuitem"]`) in its own shadow root, so focusing an item * means focusing that inner element, not the host. */ export interface MenuNavigationConfig { /** Selector for every navigable item host (without any `:not([disabled])`). */ itemSelector: string; /** * Selector matching the container of a nested submenu's items. Items inside * such a container are navigated separately from the top-level items. */ subContentSelector: string; } /** Enabled items under `root` that share the given submenu scope. */ export declare function getMenuItems(root: HTMLElement, cfg: MenuNavigationConfig, scope?: Element | null): HTMLElement[]; /** Focus an item by focusing its inner `[role=menuitem*]` element. */ export declare function focusMenuItem(item: HTMLElement | undefined | null): void; /** * Focus an item, retrying for a few frames until it is actually focused. A * submenu's content only renders its slot once it is open, so the items are * not focusable on the very frame the open was requested. */ export declare function focusMenuItemWhenReady(item: HTMLElement | undefined | null, framesLeft?: number): void; /** * Focus the first enabled top-level item. Waits for the item to be upgraded * and rendered (and for the content's slot to render) first, so it works when tags are defined one at a time (#314). */ export declare function focusFirstMenuItem(root: HTMLElement, cfg: MenuNavigationConfig): Promise; /** Deepest focused element, looking through shadow roots. */ export declare function getDeepActiveElement(): HTMLElement | null; /** True when `node` is `ancestor` or a descendant of it, crossing shadow boundaries. */ export declare function composedContains(ancestor: Node, node: Node | null): boolean; /** Mutable type-ahead state owned by one menu content instance. */ export interface TypeaheadState { buffer: string; timer?: ReturnType; } export declare function clearTypeahead(state: TypeaheadState): void; /** What `handleMenuKeyDown` found out about the event. */ export interface MenuKeyResult { /** The item host the event originated from, if any. */ target: HTMLElement | null; /** True when the event came from a nested submenu's items. */ inSubmenu: boolean; /** True when the key was consumed. */ handled: boolean; } /** * Handle ArrowDown / ArrowUp / Home / End / type-ahead for a menu. The current * item is derived from the event itself, so mouse hover, click and Tab focus * can never put a "focused index" out of sync with the DOM. * * Enter / Space are intentionally NOT handled here: every item activates * itself from its own keydown handler, and doing it twice would select twice. */ export declare function handleMenuKeyDown(event: KeyboardEvent, root: HTMLElement, cfg: MenuNavigationConfig, typeahead: TypeaheadState): MenuKeyResult;