-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref. #3 (comment)
- Loading branch information
Showing
6 changed files
with
77 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"presets": [["env", { "modules": false }]] | ||
"presets": [ | ||
["@babel/preset-env", { "modules": false }] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
/dist/ | ||
.DS_Store | ||
.DS_Store | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,76 @@ | ||
# dom-focus-lock | ||
|
||
It is a trap! We got your focus and will not let him out! | ||
|
||
[![NPM](https://nodei.co/npm/dom-focus-lock.png?downloads=true&stars=true)](https://nodei.co/npm/dom-focus-lock/) | ||
|
||
This is a small, but very useful for: | ||
|
||
- Modal dialogs. You can not leave it with "Tab", ie tab-out. | ||
- Focused tasks. It will aways brings you back. | ||
|
||
You have to use it in _every_ modal dialog, or you `a11y` will be shitty. | ||
You have to use it in _every_ modal dialog, or you accessibility will be shitty. | ||
|
||
# How to use | ||
|
||
Just include script | ||
|
||
```html | ||
<script src="http://unpkg.com/dom-focus-lock"></script> | ||
``` | ||
Or require it from js | ||
Or require it from JS | ||
|
||
```js | ||
import focusLock from 'dom-focus-lock' | ||
import focusLock from 'dom-focus-lock' | ||
``` | ||
Then - activate the lock on desired node | ||
Then, activate the lock on desired node | ||
|
||
```js | ||
focusLock.on(domNode); | ||
//..... | ||
focusLock.off(domNode); | ||
``` | ||
|
||
#WHY? | ||
# Why? | ||
|
||
From [MDN Article about accessible dialogs](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_dialog_role): | ||
|
||
- The dialog must be properly labeled | ||
- Keyboard __focus must be managed__ correctly | ||
|
||
This one is about managing the focus. | ||
|
||
I'v got a good [article about focus management, dialogs and WAI-ARIA](https://medium.com/@antonkorzunov/its-a-focus-trap-699a04d66fb5). | ||
|
||
|
||
# Behavior | ||
0. It will always keep focus inside Lock. | ||
1. It will cycle forward then you press Tab. | ||
2. It will cycle in reverse direction on Shift+Tab. | ||
3. It will do it using _browser_ tools, not emulation. | ||
4. It will handle positive tabIndex inside form. | ||
5. It will prevent any jump outside, returning focus to the last element. | ||
|
||
0. It will always keep focus inside Lock. | ||
1. It will cycle forward then you press Tab. | ||
2. It will cycle in reverse direction on Shift+Tab. | ||
3. It will do it using _browser_ tools, not emulation. | ||
4. It will handle positive tabIndex inside form. | ||
5. It will prevent any jump outside, returning focus to the last element. | ||
|
||
You can use nested Locks or have more than one Lock on the page. | ||
Only `last`, or `deepest` one will work. No fighting. | ||
|
||
# API | ||
FocusLock has only 3 props, 2 of them you will never use(I hope): | ||
- `disabled`, to disable(enable) behavior without altering the tree. | ||
|
||
FocusLock has only 3 props, 2 of them you will never use (I hope): | ||
|
||
- `disabled`, to disable(enable) behavior without altering the tree. | ||
|
||
# How it works | ||
Everything thing is simple - vue-focus-lock just dont left focus left boundaries of component, and | ||
do something only if escape attempt was succeeded. | ||
|
||
Everything is simple - dom-focus-lock just dont left focus left boundaries of component, and | ||
do something only if escape attempt was succeeded. | ||
|
||
It is not altering tabbing behavior at all. We are good citizens. | ||
It is not altering tabbing behavior at all. We are good citizens. | ||
|
||
# Not using a vanilla js? | ||
try [react-focus-lock](https://github.com/theKashey/react-focus-lock) or [vue-focus-lock](https://github.com/theKashey/vue-focus-lock) | ||
# Not using a vanilla JS? | ||
|
||
Try [react-focus-lock](https://github.com/theKashey/react-focus-lock) or [vue-focus-lock](https://github.com/theKashey/vue-focus-lock) | ||
|
||
# Licence | ||
MIT | ||
|
||
|
||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,24 +2,40 @@ | |
"name": "dom-focus-lock", | ||
"version": "1.0.3", | ||
"description": "It is a trap! (for a focus)", | ||
"author": "theKashey <[email protected]>", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"unpkg": "umd/index.js", | ||
"scripts": { | ||
"build": "rollup --config rollup.config.js", | ||
"prepublish": "npm run build", | ||
"prepublishOnly": "npm run build", | ||
"lint": "eslint src tests", | ||
"lint:fix": "eslint src tests --fix" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/theKashey/dom-focus-lock.git" | ||
"lint:fix": "eslint src tests --fix", | ||
"test": "ws --static.index example/testForm.html --open" | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"umd" | ||
], | ||
"dependencies": { | ||
"focus-lock": "^0.5.3" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.3.4", | ||
"@babel/preset-env": "^7.3.4", | ||
"eslint": "^4.6.0", | ||
"local-web-server": "^2.6.1", | ||
"rollup": "^1.5.0", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-commonjs": "^9.2.1", | ||
"rollup-plugin-node-globals": "^1.4.0", | ||
"rollup-plugin-node-resolve": "^4.0.1" | ||
}, | ||
"browserslist": [ | ||
"last 2 versions" | ||
], | ||
"keywords": [ | ||
"vanilla", | ||
"dom", | ||
|
@@ -29,32 +45,12 @@ | |
"trap", | ||
"tabbable" | ||
], | ||
"author": "theKashey <[email protected]>", | ||
"license": "ISC", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/theKashey/dom-focus-lock.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/theKashey/dom-focus-lock/issues" | ||
}, | ||
"homepage": "https://github.com/theKashey/dom-focus-lock#readme", | ||
"devDependencies": { | ||
"babel-cli": "6", | ||
"babel-core": "^6.24.0", | ||
"babel-eslint": "7.2.3", | ||
"babel-loader": "^6.4.1", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-env": "1.6.0", | ||
"babel-preset-es2015": "^6.24.0", | ||
"babel-preset-stage-2": "^6.22.0", | ||
"babel-runtime": "^6.23.0", | ||
"eslint": "^4.6.0", | ||
"eslint-plugin-vue": "^3.12.0", | ||
"rollup": "^1.5.0", | ||
"rollup-plugin-babel": "^3.0.7", | ||
"rollup-plugin-commonjs": "^9.2.1", | ||
"rollup-plugin-node-globals": "^1.4.0", | ||
"rollup-plugin-node-resolve": "^4.0.1", | ||
"style-loader": "^0.15.0" | ||
}, | ||
"dependencies": { | ||
"focus-lock": "^0.5.3" | ||
} | ||
"homepage": "https://github.com/theKashey/dom-focus-lock#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters