Edit this page

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

Focuses the given element.

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


Parameters

element
required

The element to focus.

[options.preventScroll=false]
optional

Whether to prevent changes to the scroll position.

boolean
[options.focusVisible='auto']
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 supporting browsers.

booleanstring
[options.force=false]
optional

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

boolean