getArrowNavigation
Learn how to get the Arrow Navigation instance in your project and get started with spatial navigation.
This function returns the Arrow Navigation instance, which you can use to control the navigation behavior. You can access the Arrow Navigation instance from any part of your application.
Syntax
import { getArrowNavigation } from '@arrow-navigation/core'
const navigationApi = getArrowNavigation()
Parameters
None
Returns
This function returns an object with the Arrow Navigation API. It provides the following methods and properties:
getFocusedElement
: Returns the currently focused element. DocssetFocusElement
: Sets the focus on the specified element. DocssetInitialFocusElement
: Sets the initial focus element. DocsregisterGroup
: Registers a group of elements for navigation. DocsupdateGroup
: Updates the configuration of a group. DocsregisterElement
: Registers an element inside a group. DocsupdateElement
: Updates the configuration of an element. DocsunregisterElement
: Unregisters an element. DocsresetGroupState
: Resets the state of a group. Docsdestroy
: Destroys the Arrow Navigation instance. DocsgetCurrentGroups
: Returns the currently registered groups. DocsgetGroupElements
: Returns the elements of a group. DocsgetGroupConfig
: Returns the configuration of a group. DocsgetRegisteredElements
: Returns the registered elements. DocsgetFocusedGroup
: Returns the currently focused group. DocsgetNextElement
: Returns the next element to focus. DocsgetNextGroup
: Returns the next group to focus. DocshandleDirectionPress
: Handles the arrow key press. Docson
: Adds an event listener. Docsoff
: Removes an event listener. Docs
Example
import { getArrowNavigation } from '@arrow-navigation/core'
const navigationApi = getArrowNavigation()
navigationApi.setFocusElement('element-0-0')