dap-design-system
Version:
Official design system for the DÁP (dap.gov.hu)
50 lines (49 loc) • 1.78 kB
TypeScript
/**
* Keyboard navigation utilities for dropdown/menu components
*/
export interface KeyboardNavigationItem {
setAttribute(name: string, value: string): void;
focus(): void;
click(): void;
textContent: string | null;
}
export interface KeyboardNavigationOptions {
enabledSelector: string;
onSelectionChange?: (item: HTMLElement, index: number, total: number) => void;
onItemClick?: (item: HTMLElement) => void;
}
export declare class KeyboardNavigationManager {
private _cachedItems;
private _cacheInvalidated;
private _focusedItem;
private _focusedIndex;
private _container;
private _options;
constructor(container: Element, options: KeyboardNavigationOptions);
invalidateCache(): void;
getEnabledItems(): Element[];
setFocusedItem(index: number): void;
initializeFocus(lastClickedItem?: HTMLElement): void;
handleKeyDown(event: KeyboardEvent): boolean;
reset(): void;
get focusedItem(): HTMLElement | null;
get focusedIndex(): number;
}
/**
* Creates a live region for screen reader announcements
*/
export declare function createOrUpdateLiveRegion(container: Element, announcement: string): void;
/**
* Announces current selection to screen readers
*/
export declare function announceSelection(container: Element, item: HTMLElement, position: number, total: number): void;
/**
* Standard keyboard navigation handler for dropdown/menu components
*/
export declare function createKeyboardNavigationHandler(container: Element, options: KeyboardNavigationOptions): {
manager: KeyboardNavigationManager;
handleKeyDown: (event: KeyboardEvent) => boolean;
invalidateCache: () => void;
initializeFocus: (lastClickedItem?: HTMLElement) => void;
reset: () => void;
};