UNPKG

5.74 kBTypeScriptView Raw
1/**
2 * Gets the first focusable element.
3 *
4 * @public
5 */
6export declare function getFirstFocusable(rootElement: HTMLElement, currentElement: HTMLElement, includeElementsInFocusZones?: boolean): HTMLElement | null;
7/**
8 * Gets the last focusable element.
9 *
10 * @public
11 */
12export declare function getLastFocusable(rootElement: HTMLElement, currentElement: HTMLElement, includeElementsInFocusZones?: boolean): HTMLElement | null;
13/**
14 * Gets the first tabbable element. (The difference between focusable and tabbable is that tabbable elements are
15 * focusable elements that also have tabIndex != -1.)
16 * @param rootElement - The parent element to search beneath.
17 * @param currentElement - The descendant of rootElement to start the search at. This element is the first one checked,
18 * and iteration continues forward. Typical use passes rootElement.firstChild.
19 * @param includeElementsInFocusZones - true if traversal should go into FocusZone descendants.
20 * @param checkNode - Include currentElement in search when true. Defaults to true.
21 * @public
22 */
23export declare function getFirstTabbable(rootElement: HTMLElement, currentElement: HTMLElement, includeElementsInFocusZones?: boolean, checkNode?: boolean): HTMLElement | null;
24/**
25 * Gets the last tabbable element. (The difference between focusable and tabbable is that tabbable elements are
26 * focusable elements that also have tabIndex != -1.)
27 * @param rootElement - The parent element to search beneath.
28 * @param currentElement - The descendant of rootElement to start the search at. This element is the first one checked,
29 * and iteration continues in reverse. Typical use passes rootElement.lastChild.
30 * @param includeElementsInFocusZones - true if traversal should go into FocusZone descendants.
31 * @param checkNode - Include currentElement in search when true. Defaults to true.
32 * @public
33 */
34export declare function getLastTabbable(rootElement: HTMLElement, currentElement: HTMLElement, includeElementsInFocusZones?: boolean, checkNode?: boolean): HTMLElement | null;
35/**
36 * Attempts to focus the first focusable element that is a child or child's child of the rootElement.
37 *
38 * @public
39 * @param rootElement - Element to start the search for a focusable child.
40 * @returns True if focus was set, false if it was not.
41 */
42export declare function focusFirstChild(rootElement: HTMLElement): boolean;
43/**
44 * Traverse to find the previous element.
45 * If tabbable is true, the element must have tabIndex != -1.
46 *
47 * @public
48 */
49export declare function getPreviousElement(rootElement: HTMLElement, currentElement: HTMLElement | null, checkNode?: boolean, suppressParentTraversal?: boolean, traverseChildren?: boolean, includeElementsInFocusZones?: boolean, allowFocusRoot?: boolean, tabbable?: boolean): HTMLElement | null;
50/**
51 * Traverse to find the next focusable element.
52 * If tabbable is true, the element must have tabIndex != -1.
53 *
54 * @public
55 * @param checkNode - Include currentElement in search when true.
56 */
57export declare function getNextElement(rootElement: HTMLElement, currentElement: HTMLElement | null, checkNode?: boolean, suppressParentTraversal?: boolean, suppressChildTraversal?: boolean, includeElementsInFocusZones?: boolean, allowFocusRoot?: boolean, tabbable?: boolean): HTMLElement | null;
58/**
59 * Determines if an element is visible.
60 *
61 * @public
62 */
63export declare function isElementVisible(element: HTMLElement | undefined | null): boolean;
64/**
65 * Determines if an element can receive focus programmatically or via a mouse click.
66 * If checkTabIndex is true, additionally checks to ensure the element can be focused with the tab key,
67 * meaning tabIndex != -1.
68 *
69 * @public
70 */
71export declare function isElementTabbable(element: HTMLElement, checkTabIndex?: boolean): boolean;
72/**
73 * Determines if a given element is a focus zone.
74 *
75 * @public
76 */
77export declare function isElementFocusZone(element?: HTMLElement): boolean;
78/**
79 * Determines if a given element is a focus sub zone.
80 *
81 * @public
82 */
83export declare function isElementFocusSubZone(element?: HTMLElement): boolean;
84/**
85 * Determines if an element, or any of its children, contain focus.
86 *
87 * @public
88 */
89export declare function doesElementContainFocus(element: HTMLElement): boolean;
90/**
91 * Determines if an, or any of its ancestors, sepcificies that it doesn't want focus to wrap
92 * @param element - element to start searching from
93 * @param noWrapDataAttribute - the no wrap data attribute to match (either)
94 * @returns true if focus should wrap, false otherwise
95 */
96export declare function shouldWrapFocus(element: HTMLElement, noWrapDataAttribute: 'data-no-vertical-wrap' | 'data-no-horizontal-wrap'): boolean;
97/**
98 * Sets focus to an element asynchronously. The focus will be set at the next browser repaint,
99 * meaning it won't cause any extra recalculations. If more than one focusAsync is called during one frame,
100 * only the latest called focusAsync element will actually be focused
101 * @param element - The element to focus
102 */
103export declare function focusAsync(element: HTMLElement | {
104 focus: () => void;
105} | undefined | null): void;
106/**
107 * Finds the closest focusable element via an index path from a parent. See
108 * `getElementIndexPath` for getting an index path from an element to a child.
109 */
110export declare function getFocusableByIndexPath(parent: HTMLElement, path: number[]): HTMLElement | undefined;
111/**
112 * Finds the element index path from a parent element to a child element.
113 *
114 * If you had this node structure: "A has children [B, C] and C has child D",
115 * the index path from A to D would be [1, 0], or `parent.chidren[1].children[0]`.
116 */
117export declare function getElementIndexPath(fromElement: HTMLElement, toElement: HTMLElement): number[];