focus
Focus management helpers for moving focus to the first, last, next, or previous focusable element within a container, or to a specific element by selector.
Import: @rtorcato/browser-common/focus
Example
import { focusFirst, focusNext, focusBySelector } from '@rtorcato/browser-common/focus'
// open a dialog and focus its first focusable element
focusFirst(dialog)
// advance focus within a form on Tab-like custom navigation
focusNext(form)
// jump straight to a known field
focusBySelector(form, 'input[name="email"]')
Exports
focusFirst(container)— focuses the first focusable element incontainerfocusLast(container)— focuses the last focusable element incontainerfocusNext(container)— focuses the element after the currently focused onefocusPrev(container)— focuses the element before the currently focused onefocusBySelector(container, selector)— focuses the element matchingselector
See the API reference for full signatures.