getNextElement

Commons
stable

Finds the next or previous focusable HTML element in a flat list relative to the currently focused element, with an optional visibility/condition filter.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

elements
required
Array<HTMLElement>
The flat array of elements to traverse (e.g. all focusable children in a list).
location
'next' | 'prev'
Direction of traversal. 'next' moves forward; 'prev' moves backward. Defaults to 'prev'.
condition
(el: HTMLElement) => boolean
Optional guard predicate. An element that returns false is skipped. Elements with offsetParent === null (hidden) are always skipped.

API

Return value

The value returned by this util.

The next matching element, or undefined when the boundary of the list is reached.

Usage

Examples

Ready-to-paste usage snippets.

Keyboard navigation in a list

typescript