UNPKG

@momentum-ui/react-collaboration

Version:

Cisco Momentum UI Framework for React Collaboration Applications

68 lines (67 loc) 1.74 kB
import { Direction, GoBackHandler } from './SpatialNavigationProvider.types'; /** * Track focusable elements in the app and move the focus to the next focusable element. */ export declare class SpatialNavigation { /** Root element */ private root; /** Currently focused element * Use WeakRef to avoid memory leaks * */ private activeElement; /** * Observer to track the active element changes. */ private activeElementObserver; /** * Back navigation handler * @private */ private readonly goBackHandler; constructor(goBackHandler?: GoBackHandler); /** * Mutation Observer callback */ private activeElementObserverCallback; /** * Initialize the spatial navigation. */ initActiveElement(): void; /** * Update the list of the focusable elements in the app. */ private findActiveElement; /** * Focus the next element in the given direction. * * @param direction User pressed arrow key. */ focusNext(direction: Direction): void; /** * Handle back action * * Either trigger click on goBack element if any * otherwise call default go back handler */ goBack(): void; /** * Set the active element. * * Also connect star tracking the active element. * @param element */ setActiveElement(element: HTMLElement): void; /** * Set the active element and call .focus() on it * @param element */ setActiveElementAndFocus(element: HTMLElement): void; /** * Get active (focused) element */ getActiveElement(): HTMLElement | undefined; /** * Cleanup resources */ dispose(): void; }