{"name":"focus-lock","version":"1.3.6","description":"DOM trap for a focus","main":"dist/es5/index.js","jsnext:main":"dist/es2015/index.js","module":"dist/es2015/index.js","sideEffects":false,"scripts":{"dev":"lib-builder dev","test":"jest","test:ci":"jest --runInBand --coverage","build":"lib-builder build && yarn size:report","release":"yarn build && yarn test","size":"yarn size-limit","size:report":"yarn --silent size-limit --json > .size.json","lint":"lib-builder lint","format":"lib-builder format","update":"lib-builder update","docz:dev":"docz dev","docz:build":"docz build","prepublish":"yarn build && yarn changelog","changelog":"conventional-changelog -p angular -i CHANGELOG.md -s","changelog:rewrite":"conventional-changelog -p angular -i CHANGELOG.md -s -r 0"},"repository":{"type":"git","url":"git+https://github.com/theKashey/focus-lock.git"},"keywords":["focus","trap","vanilla"],"author":{"name":"theKashey","email":"thekashey@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/theKashey/focus-lock/issues"},"homepage":"https://github.com/theKashey/focus-lock#readme","devDependencies":{"@size-limit/preset-small-lib":"^11.0.2","@theuiteam/lib-builder":"^0.1.4","size-limit":"^11.0.2"},"types":"dist/es5/index.d.ts","engines":{"node":">=10"},"dependencies":{"tslib":"^2.0.3"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.{ts,tsx}":["prettier --write","eslint --fix","git add"],"*.{js,css,json,md}":["prettier --write","git add"]},"prettier":{"printWidth":120,"trailingComma":"es5","tabWidth":2,"semi":true,"singleQuote":true},"_id":"focus-lock@1.3.6","gitHead":"0a2c083c5c2c9c546f09f27dcf42e62811688e96","_nodeVersion":"18.20.1","_npmVersion":"10.5.0","dist":{"integrity":"sha512-Ik/6OCk9RQQ0T5Xw+hKNLWrjSMtv51dD4GRmJjbD5a58TIEpI5a5iXagKVl3Z5UuyslMCA8Xwnu76jQob62Yhg==","shasum":"955eec1e10591d56f679258edb94aedb11d691cd","tarball":"http://registry-npm.ywwl.com/focus-lock/download/focus-lock-1.3.6.tgz","fileCount":166,"unpackedSize":188410,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDw/LBcyKiKJvxNT5z3sxencRTnjRe8tu6JgyVLeE+6FAIgGxtvFoxJf58wjDqoStfhYJw8QW5vn8Qx7MH4mDl2vkk="}],"size":27270,"noattachment":false,"key":"/focus-lock/-/focus-lock-1.3.6.tgz"},"_npmUser":{"name":"kashey","email":"thekashey@gmail.com"},"directories":{},"maintainers":[{"name":"kashey","email":"thekashey@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/focus-lock_1.3.6_1735956237812_0.9484806692007095"},"_hasShrinkwrap":false,"readme":"# focus-lock\n\nIt is a trap! We got your focus and will not let him out!\n\n[![NPM](https://nodei.co/npm/focus-lock.png?downloads=true&stars=true)](https://nodei.co/npm/react-focus-lock/)\n\n**Important** - this is a low level package to be used in order to create \"focus lock\".\nIt does not provide any \"lock\" capabilities by itself, only helpers you can use to create one\n\n# Focus-lock implementations\n\nThis is a base package for:\n\n- [react-focus-lock](https://github.com/theKashey/react-focus-lock)\n  [![downloads](https://badgen.net/npm/dm/react-focus-lock)](https://www.npmtrends.com/react-focus-lock)\n- [vue-focus-lock](https://github.com/theKashey/vue-focus-lock)\n  [![downloads](https://badgen.net/npm/dm/vue-focus-lock)](https://www.npmtrends.com/vue-focus-lock)\n- [dom-focus-lock](https://github.com/theKashey/dom-focus-lock)\n  [![downloads](https://badgen.net/npm/dm/dom-focus-lock)](https://www.npmtrends.com/dom-focus-lock)\n\nThe common use case will look like final realization.\n\n```js\nimport { moveFocusInside, focusInside } from 'focus-lock';\n\nif (someNode && !focusInside(someNode)) {\n  moveFocusInside(someNode, lastActiveFocus /* very important to know */);\n}\n```\n\n> note that tracking `lastActiveFocus` is on the end user.\n\n## Declarative control\n\n`focus-lock` provides not only API to be called by some other scripts, but also a way one can leave instructions inside HTML markup\nto amend focus behavior in a desired way.\n\nThese are `data-attributes` one can add on the elements:\n\n- control\n  - `data-focus-lock=[group-name]` to create a focus group (scattered focus)\n  - `data-focus-lock-disabled=\"disabled\"` marks such group as disabled and removes from the list. Equal to removing elements from the DOM.\n  - `data-no-focus-lock` focus-lock will ignore/allow focus inside marked area. Focus on this elements will not be managed by focus-lock.\n- autofocus (via `moveFocusInside(someNode, null)`)\n  - `data-autofocus` will autofocus marked element on activation.\n  - `data-autofocus-inside` focus-lock will try to autofocus elements within selected area on activation.\n  - `data-no-autofocus` focus-lock will not autofocus any node within marked area on activation.\n\nThese markers are available as `import * as markers from 'focus-lock/constants'`\n\n## Additional API\n\n### Get focusable nodes\n\nReturns visible and focusable nodes\n\n```ts\nimport { expandFocusableNodes, getFocusableNodes, getTabbleNodes } from 'focus-lock';\n\n// returns all focusable nodes inside given locations\ngetFocusableNodes([many, nodes])[0].node.focus();\n\n// returns all nodes reacheable in the \"taborder\" inside given locations\ngetTabbleNodes([many, nodes])[0].node.focus();\n\n// returns an \"extended information\" about focusable nodes inside. To be used for advances cases (react-focus-lock)\nexpandFocusableNodes(singleNodes);\n```\n\n### Programmatic focus management\n\nAllows moving back and forth between focusable/tabbable elements\n\n```ts\nimport { focusNextElement, focusPrevElement } from 'focus-lock';\nfocusNextElement(document.activeElement, {\n  scope: theBoundingDOMNode,\n}); // -> next tabbable element\n```\n\n### Return focus\n\nAdvanced API to return focus (from the Modal) to the last or the next best location\n\n```ts\nimport { captureFocusRestore } from 'focus-lock';\nconst restore = captureFocusRestore(element);\n// ....\nrestore()?.focus(); // restores focus the the element, or it's siblings in case it no longer exists\n```\n\n# WHY?\n\nFrom [MDN Article about accessible dialogs](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_dialog_role):\n\n- The dialog must be properly labeled\n- Keyboard **focus must be managed** correctly\n\nThis one is about managing the focus.\n\nI'v got a good [article about focus management, dialogs and WAI-ARIA](https://medium.com/@antonkorzunov/its-a-focus-trap-699a04d66fb5).\n\n# Focus fighting\n\nIt is possible, that more that one \"focus management system\" is present on the site.\nFor example, you are using FocusLock for your content, and also using some\nModal dialog, with FocusTrap inside.\n\nBoth system will try to do their best, and move focus into their managed areas.\nStack overflow. Both are dead.\n\nFocus Lock(React-Focus-Lock, Vue-Focus-Lock and so on) implements anti-fighting\nprotection - once the battle is detected focus-lock will surrender(as long there is no way to win this fight).\n\nYou may also land a peace by special data attribute - `data-no-focus-lock`(constants.FOCUS_ALLOW). It will\nremove focus management from all nested elements, letting you open modals, forms, or\nuse any third party component safely. Focus lock will just do nothing, while focus is on the marked elements.\n\n# API\n\n`default(topNode, lastNode)` (aka setFocus), moves focus inside topNode, keeping in mind that last focus inside was - lastNode\n\n# Licence\n\nMIT\n","publish_time":1735956237985,"_cnpm_publish_time":1735956237985,"dist-tags":{"latest":"1.3.6"}}