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.

Parameters

container

HTMLElement

The container element to search within.

Returns

boolean

True if an element was focused, false otherwise.

Example

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

focusLast()

focusLast(container): boolean

Defined in: focus/index.ts:32

Focuses the last focusable element within a container.

Parameters

container

HTMLElement

The container element to search within.

Returns

boolean

True if an element was focused, false otherwise.

Example

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

focusNext()

focusNext(container): boolean

Defined in: focus/index.ts:56

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

Parameters

container

HTMLElement

The container element to search within.

Returns

boolean

True if an element was focused, false otherwise.

Example

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

focusPrev()

focusPrev(container): boolean

Defined in: focus/index.ts:83

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

Parameters

container

HTMLElement

The container element to search within.

Returns

boolean

True if an element was focused, false otherwise.

Example

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

focusBySelector()

focusBySelector(container, selector): boolean

Defined in: focus/index.ts:111

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

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.

Example

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