Bootstrap

API navManager

createNavManager

function

createNavManager(): object

Returns a new instance of the navigation manager.

The navigation manager simplifies keyboard navigation for a set of DOM elements. It provides a directive to use on some DOM elements, both to add the keydown event handler and to specify which elements should be managed (either by directly putting the directive on those elements, or by putting the directive on a parent element and specifying which child elements should be included through a selector function).

It provides some utilities to move the focus between those elements (focusFirst/focusLast, focusLeft/focusRight, focusPrevious/focusNext).

Returns

object

a new instance of the navigation manager

directive

directive: <T>(node, args) => void | object

Type Parameters

T = any

Parameters

node: SSRHTMLElement

args: NavManagerItemConfig<T>

Returns

void | object

elementsInDomOrder$

elementsInDomOrder$: ReadableSignal<HTMLElement[]>

focusFirst

focusFirst: (__namedParameters) => null | HTMLElement

Parameters

__namedParameters = {}

__namedParameters.event?: Event

Returns

null | HTMLElement

focusFirstLeft

focusFirstLeft: (...args) => null | HTMLElement

Parameters

• ...args: [Object?]

Returns

null | HTMLElement

focusFirstRight

focusFirstRight: (...args) => null | HTMLElement

Parameters

• ...args: [Object?]

Returns

null | HTMLElement

focusIndex

focusIndex: (index, moveDirection) => null | HTMLElement

Parameters

index: number

moveDirection: -1 | 0 | 1 = 0

Returns

null | HTMLElement

focusLast

focusLast: (__namedParameters) => null | HTMLElement

Parameters

__namedParameters = {}

__namedParameters.event?: Event

Returns

null | HTMLElement

focusLeft

focusLeft: (...args) => null | HTMLElement

Parameters

• ...args: [Object?]

Returns

null | HTMLElement

focusNext

focusNext: (__namedParameters) => null | HTMLElement

Parameters

__namedParameters = {}

__namedParameters.event?: Event

__namedParameters.referenceElement?: null | HTMLElement = ...

Returns

null | HTMLElement

focusPrevious

focusPrevious: (__namedParameters) => null | HTMLElement

Parameters

__namedParameters = {}

__namedParameters.event?: Event

__namedParameters.referenceElement?: null | HTMLElement = ...

Returns

null | HTMLElement

focusRight

focusRight: (...args) => null | HTMLElement

Parameters

• ...args: [Object?]

Returns

null | HTMLElement

refreshElements

refreshElements: (now) => void

Parameters

now: boolean = true

Returns

void


getKeyName

function

getKeyName(event): string

Returns the key name given the keyboard event. The key name is built using event.key (such as ArrowLeft, PageDown...), prefixed with the modifiers. If present, modifiers are always in the same order: Meta+Ctrl+Alt+Shift+...

Parameters

event: KeyboardEvent

keyboard event

Returns

string

the name of the key, including modifiers


isInternalInputNavigation

function

isInternalInputNavigation(event): boolean

Returns true if the keyboard event is an ArrowLeft, ArrowRight, Home or End key press that should make the cursor move inside the input and false otherwise (i.e. the key is not ArrowLeft, ArrowRight, Home or End key, or that would not make the cursor move because it is already at one end of the input)

Parameters

event: KeyboardEvent

keyboard event

Returns

boolean

true if the keyboard event is an ArrowLeft, ArrowRight, Home or End key press that should make the cursor move inside the input and false otherwise.


type alias

NavManager: ReturnType<*typeof* createNavManager>


interface

Type of the parameter of the navigation manager directive.

Type Parameters

T = any

Properties

optional context: T


optional keys: Record<string, NavManagerKeyHandler<T>>

Map of key handlers. The key in the map should match the result of calling getKeyName on the key event (for example "ArrowLeft" or "Ctrl+PageDown"). The value in the map is the corresponding key handler.


optional selector: (directiveElement) => Iterable<HTMLElement>

Function returning DOM elements to include in the navigation manager. It receives as a parameter the DOM element on which the navigation manager directive is used. If not specified, the default selector function only returns the element on which the navigation manager directive is used.

Parameters

directiveElement: HTMLElement

Returns

Iterable<HTMLElement>


type alias

NavManagerKeyHandler<T>: (info) => void

Type of a key handler of the navigation manager. A key handler receives an object as its parameter, with the following properties:

  • event: key event
  • directiveElement: DOM element which has the navigation manager directive
  • navManager: navigation manager instance
Type Parameters

T = any

Parameters

info

info.context?: T

info.directiveElement: HTMLElement

info.event: Event

info.navManager: NavManager

Returns

void