Edit this page

up.viewport up.focus(element, [options])
JavaScript function

This feature is experimental. It may be changed or removed in a future version.

Focuses the given element.

Focusing an element will also reveal it, unless { preventScroll: true } is passed.

Parameters

element stringorElementorjQuery

The element to focus.

[options.preventScroll=false] boolean optional

Whether to prevent changes to the acroll position.

[options.focusVisible='auto'] booleanorstring optional

Whether the focused element should have a visible focus ring.

If set to true the element will be assigned the .up-focus-visible class.

If set to false the element will be assigned the .up-focus-hidden class.

If set to 'auto' (the default), focus will be visible if up.viewport.config.autoFocusVisible() returns true for the given element and current input device.

The :focus-visible pseudo-class will also be set or removed accordingly on browsers that support it.

[options.force=false] boolean optional

Whether to force focus even if element would otherwise not be a focusable element.