Skip to main content

@rtorcato/browser-common / focus

focus

Functions​

focusFirst()​

focusFirst(container): boolean

Defined in: focus/index.ts:11

Focuses the first focusable element within a container.

Example​

import { focusFirst } from '@rtorcato/browser-common/focus'
focusFirst(dialog)

Parameters​

container​

HTMLElement

The container element to search within.

Returns​

boolean

True if an element was focused, false otherwise.


focusLast()​

focusLast(container): boolean

Defined in: focus/index.ts:32

Focuses the last focusable element within a container.

Example​

import { focusLast } from '@rtorcato/browser-common/focus'
focusLast(dialog)

Parameters​

container​

HTMLElement

The container element to search within.

Returns​

boolean

True if an element was focused, false otherwise.


focusNext()​

focusNext(container): boolean

Defined in: focus/index.ts:56

Focuses the next focusable element after the currently focused element within a container.

Example​

import { focusNext } from '@rtorcato/browser-common/focus'
focusNext(form)

Parameters​

container​

HTMLElement

The container element to search within.

Returns​

boolean

True if an element was focused, false otherwise.


focusPrev()​

focusPrev(container): boolean

Defined in: focus/index.ts:83

Focuses the previous focusable element before the currently focused element within a container.

Example​

import { focusPrev } from '@rtorcato/browser-common/focus'
focusPrev(form)

Parameters​

container​

HTMLElement

The container element to search within.

Returns​

boolean

True if an element was focused, false otherwise.


focusBySelector()​

focusBySelector(container, selector): boolean

Defined in: focus/index.ts:111

Sets focus to a specific element by selector within a container.

Example​

import { focusBySelector } from '@rtorcato/browser-common/focus'
focusBySelector(form, 'input[name="email"]')

Parameters​

container​

HTMLElement

The container element to search within.

selector​

string

The CSS selector for the element to focus.

Returns​

boolean

True if an element was focused, false otherwise.