$ cnpm install focus-lock
It is a trap! We got your focus and will not let him out!
This is a base package for:
Provides a low level API, to be used by final realization. Usually everything can be solved in 3 lines
import moveFocusInside, { focusInside } from 'focus-lock';
if (topNode && !focusInside(topNode)) {
moveFocusInside(topNode, lastActiveFocus);
}
import { focusNextElement, focusPrevElement } from 'focus-lock';
focusNextElement(sourceElement, {
scope: theBoundingDOMNode,
}); // -> next tabbable element
From MDN Article about accessible dialogs:
This one is about managing the focus.
I'v got a good article about focus management, dialogs and WAI-ARIA.
Focus-lock
provides not only API to be called by some other scripts, but also a way one can leave instructions inside HTML markup
to amend focus behavior in a desired way.
These are data-attributes one can add on the elements:
data-focus-lock
to create a focus group (scattered focus)data-focus-lock-disabled
marks such group as disables and removes from the listdata-no-focus-lock
focus-lock will ignore focus inside marked areadata-autofocus-inside
focus-lock will try to autofocus elements within selected areadata-no-autofocus
focus-lock will not autofocus any node within marked areaThese markers are available as import * as markers from 'focus-lock/constants'
It is possible, that more that one "focus management system" is present on the site. For example, you are using FocusLock for your content, and also using some Modal dialog, with FocusTrap inside.
Both system will try to do their best, and move focus into their managed areas. Stack overflow. Both are dead.
Focus Lock(React-Focus-Lock, Vue-Focus-Lock and so on) implements anti-fighting protection - once the battle is detected focus-lock will surrender(as long there is no way to win this fight).
You may also land a peace by special data attribute - data-no-focus-lock
(constants.FOCUS_ALLOW). It will
remove focus management from all nested elements, letting you open modals, forms, or
use any third party component safely. Focus lock will just do nothing, while focus is on the marked elements.
default(topNode, lastNode)
(aka setFocus), moves focus inside topNode, keeping in mind that last focus inside was - lastNode
MIT
Copyright 2013 - present © cnpmjs.org