Gathering detailed insights and metrics for focus-lock
Gathering detailed insights and metrics for focus-lock
Gathering detailed insights and metrics for focus-lock
Gathering detailed insights and metrics for focus-lock
npm install focus-lock
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.7
Supply Chain
100
Quality
77.1
Maintenance
100
Vulnerability
100
License
TypeScript (97.91%)
JavaScript (2.09%)
Total Downloads
597,988,492
Last Day
107,052
Last Week
2,337,668
Last Month
10,087,647
Last Year
114,363,180
MIT License
180 Stars
225 Commits
19 Forks
4 Watchers
23 Branches
14 Contributors
Updated on Jun 18, 2025
Minified
Minified + Gzipped
Latest Version
1.3.6
Package Id
focus-lock@1.3.6
Unpacked Size
183.99 kB
Size
26.63 kB
File Count
166
NPM Version
10.5.0
Node Version
18.20.1
Published on
Jan 04, 2025
Cumulative downloads
Total Downloads
1
3
It is a trap! We got your focus and will not let him out!
Important - this is a low level package to be used in order to create "focus lock". It does not provide any "lock" capabilities by itself, only helpers you can use to create one
This is a base package for:
The common use case will look like final realization.
1import { moveFocusInside, focusInside } from 'focus-lock';
2
3if (someNode && !focusInside(someNode)) {
4 moveFocusInside(someNode, lastActiveFocus /* very important to know */);
5}
note that tracking
lastActiveFocus
is on the end user.
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=[group-name]
to create a focus group (scattered focus)data-focus-lock-disabled="disabled"
marks such group as disabled and removes from the list. Equal to removing elements from the DOM.data-no-focus-lock
focus-lock will ignore/allow focus inside marked area. Focus on this elements will not be managed by focus-lock.moveFocusInside(someNode, null)
)
data-autofocus
will autofocus marked element on activation.data-autofocus-inside
focus-lock will try to autofocus elements within selected area on activation.data-no-autofocus
focus-lock will not autofocus any node within marked area on activation.These markers are available as import * as markers from 'focus-lock/constants'
Returns visible and focusable nodes
1import { expandFocusableNodes, getFocusableNodes, getTabbleNodes } from 'focus-lock'; 2 3// returns all focusable nodes inside given locations 4getFocusableNodes([many, nodes])[0].node.focus(); 5 6// returns all nodes reacheable in the "taborder" inside given locations 7getTabbleNodes([many, nodes])[0].node.focus(); 8 9// returns an "extended information" about focusable nodes inside. To be used for advances cases (react-focus-lock) 10expandFocusableNodes(singleNodes);
Allows moving back and forth between focusable/tabbable elements
1import { focusNextElement, focusPrevElement } from 'focus-lock';
2focusNextElement(document.activeElement, {
3 scope: theBoundingDOMNode,
4}); // -> next tabbable element
Advanced API to return focus (from the Modal) to the last or the next best location
1import { captureFocusRestore } from 'focus-lock'; 2const restore = captureFocusRestore(element); 3// .... 4restore()?.focus(); // restores focus the the element, or it's siblings in case it no longer exists
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.
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
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/25 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
69 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
-10.6%
107,052
Compared to previous day
Last Week
-7.2%
2,337,668
Compared to previous week
Last Month
1.8%
10,087,647
Compared to previous month
Last Year
-8.4%
114,363,180
Compared to previous year