@jobber/hooks 2.3.0 → 2.4.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.
|
@@ -34,10 +34,10 @@ function useFocusTrap(active) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
(0, react_1.useEffect)(() => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
if (active && ref.current) {
|
|
38
|
+
const { firstElement } = getElements(ref.current);
|
|
39
|
+
firstElement.focus();
|
|
40
|
+
ref.current.addEventListener("keydown", handleKeyDown);
|
|
41
41
|
}
|
|
42
42
|
return () => {
|
|
43
43
|
var _a;
|
|
@@ -56,8 +56,14 @@ function getElements(ref) {
|
|
|
56
56
|
"textarea",
|
|
57
57
|
'[tabindex]:not([tabindex="-1"])',
|
|
58
58
|
];
|
|
59
|
-
const elements =
|
|
60
|
-
|
|
59
|
+
const elements = [
|
|
60
|
+
...ref.querySelectorAll(focusables.join(", ")),
|
|
61
|
+
];
|
|
62
|
+
// If the ref is focusable, ensure it's the first element to be focused.
|
|
63
|
+
if (ref.getAttribute("tabindex") === "0") {
|
|
64
|
+
elements.unshift(ref);
|
|
65
|
+
}
|
|
66
|
+
const firstElement = elements[0];
|
|
61
67
|
const lastElement = elements[elements.length - 1];
|
|
62
68
|
return { firstElement, lastElement };
|
|
63
69
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/hooks",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.js",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"@apollo/client": "^3.0.0",
|
|
46
46
|
"react": "^18"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "f9530a9ef052c5a914c9c9270260b372b720ecf4"
|
|
49
49
|
}
|