/** * @file * Utilities for managing focus in the browser. */ /** * Determines whether an html element is considered hidden based on its dimensions or computed visibility style. * * This function is primarily used in environments where accurate layout-related properties * are available, like a real browser environment. * * @param {HTMLElement} element - The DOM element to check for visibility. * @returns {boolean} - Returns true if the element is hidden, otherwise false. * * @private Exported for testing purposes */ export declare const isHidden: (element: HTMLElement) => boolean; /** * Sorts the tabbable elements in the provided container. * * @param {Element} container - The target container. * @param {Object} [options={ignoreTabIndex: false}] - Configuration options. * @param {boolean} [options.ignoreTabIndex=false] - If set to true, the function will neither use "tabindex" as an indicator of selectability nor disqualify elements based on "tabindex=-1". * @returns {HTMLElement[]} A sorted array of tabbable elements within the container. * @public */ export declare function getSortedTabbableElements(container: Element, { ignoreTabIndex }?: { ignoreTabIndex?: boolean; }): HTMLElement[]; export declare function isTabKey(event: KeyboardEvent): boolean; /** * A key event handler that moves focus among tabbable elements within a container. * * @param {Element} container - The target container. * @param {Event} event - The key event to handle. * @returns {HTMLElement|null} The element focus was applied to or `null` if focus was not applied. * @public */ export declare function handleTab(container: Element, event: KeyboardEvent): Element | null; /** * A helper method that focuses on the first focusable element in a container. * If a contained element already has focus, focus does not shift. * * @param {HTMLElement} container - The container that takes focus. * @param {String} [defaultElement='first'] - The target of focus, either 'first' or 'container'. * @returns {Element|null} The element that was focused, or null if no element was focused. * @public */ export declare function takeFocus(container: HTMLElement, defaultElement?: 'first' | 'container'): Element | null; /** * Helper function to calculate the new index from the current index. * * This function determines the new index for focus navigation based on the current index, * the direction of movement, and whether looping is enabled. It either caps at the start/end * of the array or loops around based on the `enableLoop` flag. * * @returns {number} - The new index. Returns the current index for invalid direction or out-of-bounds index when looping is disabled. */ export declare const calculateIndex: ({ itemsLength, currentIndex, direction, enableLoop, }: { itemsLength: number; currentIndex: number; direction: "none" | "next" | "previous"; enableLoop: boolean; }) => number; /** * Helper function to get the new focusable index in the items array based on the key. * * This function calculates the next focusable index in a list of items, depending on the provided key * (e.g. arrow keys, Home, End, Tab). It takes into account the current focus index, orientation of navigation * (horizontal or vertical), looping behavior, and specific key handling rules. * * @returns {number} - The new focusable index. Returns -1 if no valid index is found. */ export declare const getNewIndex: (key: KeyboardEvent["key"], itemsLength: number, currentIndex: number, { enableLoop, orientation, enableTab, enableHomeEnd, }: { enableLoop: boolean; orientation: "horizontal" | "vertical"; enableTab: boolean; enableHomeEnd: boolean; }) => number; /** * Helper function to update the tabindex of action items, setting the active item to be focusable */ export declare const updateTabIndex: (activeIndex: number, actionItems: HTMLElement[]) => void; /** * Handles focus navigation for a list of action items based on key presses. * * @param {string} key - The key value obtained from KeyboardEvent.key, representing the keyboard key pressed. * @param {Element[]} actionItems - An array of HTML elements representing the action items. * @param {number} currentIndex - The current index of the focused item. * @param {Object} [options={ enableLoop: false, orientation: 'horizontal', enableTab: false, enableHomeEnd: true }] - Configuration options. * @param {boolean} [options.enableLoop=false] - Whether navigation should loop around the ends of the list. * @param {string} [options.orientation='horizontal'] - Navigation orientation: 'horizontal' (left/right arrow keys) or 'vertical' (up/down arrow keys). * @param {boolean} [options.enableTab=false] - Enable navigation with the Tab key. * @param {boolean} [options.enableHomeEnd=true] - Enable navigation with Home and End keys. * @public */ export declare function handleFocus(key: KeyboardEvent['key'], actionItems: HTMLElement[], currentIndex: number, { enableLoop, orientation, enableTab, enableHomeEnd, }?: { enableLoop?: boolean; orientation?: 'horizontal' | 'vertical'; enableTab?: boolean; enableHomeEnd?: boolean; }): void;