@uifabric/utilities
Version:
Fluent UI React utilities for building components.
118 lines (117 loc) • 5.74 kB
TypeScript
/**
* Gets the first focusable element.
*
* @public
*/
export declare function getFirstFocusable(rootElement: HTMLElement, currentElement: HTMLElement, includeElementsInFocusZones?: boolean): HTMLElement | null;
/**
* Gets the last focusable element.
*
* @public
*/
export declare function getLastFocusable(rootElement: HTMLElement, currentElement: HTMLElement, includeElementsInFocusZones?: boolean): HTMLElement | null;
/**
* Gets the first tabbable element. (The difference between focusable and tabbable is that tabbable elements are
* focusable elements that also have tabIndex != -1.)
* @param rootElement - The parent element to search beneath.
* @param currentElement - The descendant of rootElement to start the search at. This element is the first one checked,
* and iteration continues forward. Typical use passes rootElement.firstChild.
* @param includeElementsInFocusZones - true if traversal should go into FocusZone descendants.
* @param checkNode - Include currentElement in search when true. Defaults to true.
* @public
*/
export declare function getFirstTabbable(rootElement: HTMLElement, currentElement: HTMLElement, includeElementsInFocusZones?: boolean, checkNode?: boolean): HTMLElement | null;
/**
* Gets the last tabbable element. (The difference between focusable and tabbable is that tabbable elements are
* focusable elements that also have tabIndex != -1.)
* @param rootElement - The parent element to search beneath.
* @param currentElement - The descendant of rootElement to start the search at. This element is the first one checked,
* and iteration continues in reverse. Typical use passes rootElement.lastChild.
* @param includeElementsInFocusZones - true if traversal should go into FocusZone descendants.
* @param checkNode - Include currentElement in search when true. Defaults to true.
* @public
*/
export declare function getLastTabbable(rootElement: HTMLElement, currentElement: HTMLElement, includeElementsInFocusZones?: boolean, checkNode?: boolean): HTMLElement | null;
/**
* Attempts to focus the first focusable element that is a child or child's child of the rootElement.
*
* @public
* @param rootElement - Element to start the search for a focusable child.
* @returns True if focus was set, false if it was not.
*/
export declare function focusFirstChild(rootElement: HTMLElement): boolean;
/**
* Traverse to find the previous element.
* If tabbable is true, the element must have tabIndex != -1.
*
* @public
*/
export declare function getPreviousElement(rootElement: HTMLElement, currentElement: HTMLElement | null, checkNode?: boolean, suppressParentTraversal?: boolean, traverseChildren?: boolean, includeElementsInFocusZones?: boolean, allowFocusRoot?: boolean, tabbable?: boolean): HTMLElement | null;
/**
* Traverse to find the next focusable element.
* If tabbable is true, the element must have tabIndex != -1.
*
* @public
* @param checkNode - Include currentElement in search when true.
*/
export declare function getNextElement(rootElement: HTMLElement, currentElement: HTMLElement | null, checkNode?: boolean, suppressParentTraversal?: boolean, suppressChildTraversal?: boolean, includeElementsInFocusZones?: boolean, allowFocusRoot?: boolean, tabbable?: boolean): HTMLElement | null;
/**
* Determines if an element is visible.
*
* @public
*/
export declare function isElementVisible(element: HTMLElement | undefined | null): boolean;
/**
* Determines if an element can receive focus programmatically or via a mouse click.
* If checkTabIndex is true, additionally checks to ensure the element can be focused with the tab key,
* meaning tabIndex != -1.
*
* @public
*/
export declare function isElementTabbable(element: HTMLElement, checkTabIndex?: boolean): boolean;
/**
* Determines if a given element is a focus zone.
*
* @public
*/
export declare function isElementFocusZone(element?: HTMLElement): boolean;
/**
* Determines if a given element is a focus sub zone.
*
* @public
*/
export declare function isElementFocusSubZone(element?: HTMLElement): boolean;
/**
* Determines if an element, or any of its children, contain focus.
*
* @public
*/
export declare function doesElementContainFocus(element: HTMLElement): boolean;
/**
* Determines if an, or any of its ancestors, sepcificies that it doesn't want focus to wrap
* @param element - element to start searching from
* @param noWrapDataAttribute - the no wrap data attribute to match (either)
* @returns true if focus should wrap, false otherwise
*/
export declare function shouldWrapFocus(element: HTMLElement, noWrapDataAttribute: 'data-no-vertical-wrap' | 'data-no-horizontal-wrap'): boolean;
/**
* Sets focus to an element asynchronously. The focus will be set at the next browser repaint,
* meaning it won't cause any extra recalculations. If more than one focusAsync is called during one frame,
* only the latest called focusAsync element will actually be focused
* @param element - The element to focus
*/
export declare function focusAsync(element: HTMLElement | {
focus: () => void;
} | undefined | null): void;
/**
* Finds the closest focusable element via an index path from a parent. See
* `getElementIndexPath` for getting an index path from an element to a child.
*/
export declare function getFocusableByIndexPath(parent: HTMLElement, path: number[]): HTMLElement | undefined;
/**
* Finds the element index path from a parent element to a child element.
*
* If you had this node structure: "A has children [B, C] and C has child D",
* the index path from A to D would be [1, 0], or `parent.chidren[1].children[0]`.
*/
export declare function getElementIndexPath(fromElement: HTMLElement, toElement: HTMLElement): number[];