focus-trap 7.0.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +39 -31
- package/dist/focus-trap.esm.js +82 -155
- package/dist/focus-trap.esm.js.map +1 -1
- package/dist/focus-trap.esm.min.js +2 -2
- package/dist/focus-trap.esm.min.js.map +1 -1
- package/dist/focus-trap.js +82 -155
- package/dist/focus-trap.js.map +1 -1
- package/dist/focus-trap.min.js +2 -2
- package/dist/focus-trap.min.js.map +1 -1
- package/dist/focus-trap.umd.js +82 -155
- package/dist/focus-trap.umd.js.map +1 -1
- package/dist/focus-trap.umd.min.js +2 -2
- package/dist/focus-trap.umd.min.js.map +1 -1
- package/index.d.ts +21 -5
- package/index.js +32 -31
- package/package.json +17 -17
package/index.js
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
import { tabbable, focusable, isFocusable, isTabbable } from 'tabbable';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
3
|
+
const rooTrapStack = [];
|
|
4
|
+
|
|
5
|
+
const activeFocusTraps = {
|
|
6
|
+
activateTrap(trapStack, trap) {
|
|
7
|
+
if (trapStack.length > 0) {
|
|
8
|
+
const activeTrap = trapStack[trapStack.length - 1];
|
|
9
|
+
if (activeTrap !== trap) {
|
|
10
|
+
activeTrap.pause();
|
|
12
11
|
}
|
|
12
|
+
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
const trapIndex = trapStack.indexOf(trap);
|
|
15
|
+
if (trapIndex === -1) {
|
|
16
|
+
trapStack.push(trap);
|
|
17
|
+
} else {
|
|
18
|
+
// move this existing trap to the front of the queue
|
|
19
|
+
trapStack.splice(trapIndex, 1);
|
|
20
|
+
trapStack.push(trap);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
deactivateTrap(trapStack, trap) {
|
|
25
|
+
const trapIndex = trapStack.indexOf(trap);
|
|
26
|
+
if (trapIndex !== -1) {
|
|
27
|
+
trapStack.splice(trapIndex, 1);
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})();
|
|
30
|
+
if (trapStack.length > 0) {
|
|
31
|
+
trapStack[trapStack.length - 1].unpause();
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
36
35
|
|
|
37
36
|
const isSelectableInput = function (node) {
|
|
38
37
|
return (
|
|
@@ -100,6 +99,8 @@ const createFocusTrap = function (elements, userOptions) {
|
|
|
100
99
|
// should be safe code to execute if the `document` option isn't specified
|
|
101
100
|
const doc = userOptions?.document || document;
|
|
102
101
|
|
|
102
|
+
const trapStack = userOptions?.trapStack || rooTrapStack;
|
|
103
|
+
|
|
103
104
|
const config = {
|
|
104
105
|
returnFocusOnDeactivate: true,
|
|
105
106
|
escapeDeactivates: true,
|
|
@@ -582,7 +583,7 @@ const createFocusTrap = function (elements, userOptions) {
|
|
|
582
583
|
}
|
|
583
584
|
|
|
584
585
|
// There can be only one listening focus trap at a time
|
|
585
|
-
activeFocusTraps.activateTrap(trap);
|
|
586
|
+
activeFocusTraps.activateTrap(trapStack, trap);
|
|
586
587
|
|
|
587
588
|
// Delay ensures that the focused element doesn't capture the event
|
|
588
589
|
// that caused the focus trap activation.
|
|
@@ -702,7 +703,7 @@ const createFocusTrap = function (elements, userOptions) {
|
|
|
702
703
|
state.active = false;
|
|
703
704
|
state.paused = false;
|
|
704
705
|
|
|
705
|
-
activeFocusTraps.deactivateTrap(trap);
|
|
706
|
+
activeFocusTraps.deactivateTrap(trapStack, trap);
|
|
706
707
|
|
|
707
708
|
const onDeactivate = getOption(options, 'onDeactivate');
|
|
708
709
|
const onPostDeactivate = getOption(options, 'onPostDeactivate');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "focus-trap",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Trap focus within a DOM node.",
|
|
5
5
|
"main": "dist/focus-trap.js",
|
|
6
6
|
"module": "dist/focus-trap.esm.js",
|
|
@@ -63,37 +63,37 @@
|
|
|
63
63
|
},
|
|
64
64
|
"homepage": "https://github.com/focus-trap/focus-trap#readme",
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"tabbable": "^6.0.
|
|
66
|
+
"tabbable": "^6.0.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@babel/cli": "^7.
|
|
70
|
-
"@babel/core": "^7.
|
|
71
|
-
"@babel/eslint-parser": "^7.
|
|
72
|
-
"@babel/preset-env": "^7.
|
|
73
|
-
"@changesets/cli": "^2.
|
|
74
|
-
"@rollup/plugin-babel": "^
|
|
75
|
-
"@rollup/plugin-commonjs": "^
|
|
76
|
-
"@rollup/plugin-node-resolve": "^
|
|
69
|
+
"@babel/cli": "^7.19.3",
|
|
70
|
+
"@babel/core": "^7.20.2",
|
|
71
|
+
"@babel/eslint-parser": "^7.19.1",
|
|
72
|
+
"@babel/preset-env": "^7.20.2",
|
|
73
|
+
"@changesets/cli": "^2.25.2",
|
|
74
|
+
"@rollup/plugin-babel": "^6.0.2",
|
|
75
|
+
"@rollup/plugin-commonjs": "^23.0.2",
|
|
76
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
77
77
|
"@testing-library/cypress": "^8.0.3",
|
|
78
78
|
"@types/jquery": "^3.5.14",
|
|
79
|
-
"all-contributors-cli": "^6.
|
|
80
|
-
"babel-loader": "^
|
|
79
|
+
"all-contributors-cli": "^6.24.0",
|
|
80
|
+
"babel-loader": "^9.1.0",
|
|
81
81
|
"cross-env": "^7.0.3",
|
|
82
|
-
"cypress": "^10.
|
|
82
|
+
"cypress": "^10.11.0",
|
|
83
83
|
"cypress-plugin-tab": "^1.0.5",
|
|
84
|
-
"eslint": "^8.
|
|
84
|
+
"eslint": "^8.27.0",
|
|
85
85
|
"eslint-config-prettier": "^8.5.0",
|
|
86
86
|
"eslint-plugin-cypress": "^2.12.1",
|
|
87
|
-
"eslint-plugin-jest": "^
|
|
87
|
+
"eslint-plugin-jest": "^27.1.4",
|
|
88
88
|
"onchange": "^7.1.0",
|
|
89
89
|
"prettier": "^2.7.1",
|
|
90
|
-
"rollup": "^2.
|
|
90
|
+
"rollup": "^2.79.1",
|
|
91
91
|
"rollup-plugin-inject-process-env": "^1.3.1",
|
|
92
92
|
"rollup-plugin-livereload": "^2.0.5",
|
|
93
93
|
"rollup-plugin-serve": "^2.0.1",
|
|
94
94
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
95
95
|
"rollup-plugin-terser": "^7.0.1",
|
|
96
96
|
"start-server-and-test": "^1.14.0",
|
|
97
|
-
"typescript": "^4.
|
|
97
|
+
"typescript": "^4.8.4"
|
|
98
98
|
}
|
|
99
99
|
}
|