@inertiaui/vanilla 1.0.0 → 1.0.3
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/README.md +4 -4
- package/dist/index.js +16 -5
- package/package.json +55 -58
package/README.md
CHANGED
|
@@ -1053,7 +1053,7 @@ const isActive = sameUrlPath(window.location.href, linkHref)
|
|
|
1053
1053
|
Start Vite to browse the interactive test pages:
|
|
1054
1054
|
|
|
1055
1055
|
```bash
|
|
1056
|
-
|
|
1056
|
+
pnpm exec vite --port 3333
|
|
1057
1057
|
```
|
|
1058
1058
|
|
|
1059
1059
|
Then open `http://localhost:3333` for an overview linking to all test pages.
|
|
@@ -1063,19 +1063,19 @@ Then open `http://localhost:3333` for an overview linking to all test pages.
|
|
|
1063
1063
|
The test suite uses Playwright with Chromium. It automatically starts a Vite dev server:
|
|
1064
1064
|
|
|
1065
1065
|
```bash
|
|
1066
|
-
|
|
1066
|
+
pnpm test:e2e
|
|
1067
1067
|
```
|
|
1068
1068
|
|
|
1069
1069
|
Run a single spec:
|
|
1070
1070
|
|
|
1071
1071
|
```bash
|
|
1072
|
-
|
|
1072
|
+
pnpm exec playwright test e2e/menu.spec.ts
|
|
1073
1073
|
```
|
|
1074
1074
|
|
|
1075
1075
|
Run tests matching a name:
|
|
1076
1076
|
|
|
1077
1077
|
```bash
|
|
1078
|
-
|
|
1078
|
+
pnpm exec playwright test -g "ArrowDown"
|
|
1079
1079
|
```
|
|
1080
1080
|
|
|
1081
1081
|
### Test structure
|
package/dist/index.js
CHANGED
|
@@ -156,6 +156,13 @@ function getFocusableElements(container) {
|
|
|
156
156
|
return Array.from(container.querySelectorAll(FOCUSABLE_SELECTORS)).filter((el) => el.getAttribute("aria-hidden") !== "true");
|
|
157
157
|
}
|
|
158
158
|
var focusTrapStack = [];
|
|
159
|
+
var lastPointerDownTarget = null;
|
|
160
|
+
function trackPointerDown(event) {
|
|
161
|
+
lastPointerDownTarget = event.target;
|
|
162
|
+
setTimeout(() => {
|
|
163
|
+
if (lastPointerDownTarget === event.target) lastPointerDownTarget = null;
|
|
164
|
+
}, 0);
|
|
165
|
+
}
|
|
159
166
|
function handleTrapKeyDown(event) {
|
|
160
167
|
if (event.key !== "Tab" || focusTrapStack.length === 0) return;
|
|
161
168
|
const { container } = focusTrapStack[focusTrapStack.length - 1];
|
|
@@ -178,7 +185,7 @@ function handleTrapFocusIn(event) {
|
|
|
178
185
|
const { container } = focusTrapStack[focusTrapStack.length - 1];
|
|
179
186
|
if (!container.contains(event.target)) {
|
|
180
187
|
const focusableElements = getFocusableElements(container);
|
|
181
|
-
if (focusableElements.length > 0) focusableElements[0].focus();
|
|
188
|
+
if (focusableElements.length > 0) focusableElements[0].focus({ preventScroll: true });
|
|
182
189
|
}
|
|
183
190
|
}
|
|
184
191
|
function createFocusTrap(container, options = {}) {
|
|
@@ -188,15 +195,17 @@ function createFocusTrap(container, options = {}) {
|
|
|
188
195
|
if (focusTrapStack.length === 0) {
|
|
189
196
|
document.addEventListener("keydown", handleTrapKeyDown);
|
|
190
197
|
document.addEventListener("focusin", handleTrapFocusIn);
|
|
198
|
+
document.addEventListener("pointerdown", trackPointerDown, true);
|
|
191
199
|
}
|
|
192
200
|
focusTrapStack.push(entry);
|
|
193
201
|
function handleFocusOut(event) {
|
|
194
202
|
if (event.relatedTarget !== null) return;
|
|
203
|
+
const pointerTarget = lastPointerDownTarget;
|
|
195
204
|
queueMicrotask(() => {
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
205
|
+
if (container.contains(container.ownerDocument.activeElement)) return;
|
|
206
|
+
if (pointerTarget instanceof Node && container.contains(pointerTarget)) return;
|
|
207
|
+
const focusableElements = getFocusableElements(container);
|
|
208
|
+
if (focusableElements.length > 0) focusableElements[0].focus({ preventScroll: true });
|
|
200
209
|
});
|
|
201
210
|
}
|
|
202
211
|
container.addEventListener("focusout", handleFocusOut);
|
|
@@ -220,6 +229,8 @@ function createFocusTrap(container, options = {}) {
|
|
|
220
229
|
if (focusTrapStack.length === 0) {
|
|
221
230
|
document.removeEventListener("keydown", handleTrapKeyDown);
|
|
222
231
|
document.removeEventListener("focusin", handleTrapFocusIn);
|
|
232
|
+
document.removeEventListener("pointerdown", trackPointerDown, true);
|
|
233
|
+
lastPointerDownTarget = null;
|
|
223
234
|
}
|
|
224
235
|
if (returnFocus && previouslyFocused && typeof previouslyFocused.focus === "function" && previouslyFocused.isConnected) previouslyFocused.focus();
|
|
225
236
|
};
|
package/package.json
CHANGED
|
@@ -1,60 +1,57 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "https://github.com/inertiaui/vanilla"
|
|
23
|
-
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
"dialog",
|
|
26
|
-
"focus-trap",
|
|
27
|
-
"scroll-lock",
|
|
28
|
-
"aria-hidden",
|
|
29
|
-
"animation",
|
|
30
|
-
"web-animations-api",
|
|
31
|
-
"accessibility",
|
|
32
|
-
"a11y",
|
|
33
|
-
"vanilla-js",
|
|
34
|
-
"typescript"
|
|
35
|
-
],
|
|
36
|
-
"scripts": {
|
|
37
|
-
"dev": "vite build --watch",
|
|
38
|
-
"build": "vite build",
|
|
39
|
-
"lint": "eslint src/",
|
|
40
|
-
"format": "prettier --write src/ e2e/",
|
|
41
|
-
"format:check": "prettier --check src/ e2e/",
|
|
42
|
-
"test": "vitest",
|
|
43
|
-
"test:e2e": "playwright test",
|
|
44
|
-
"prepublishOnly": "npm run build"
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@playwright/test": "^1.58.2",
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
49
|
-
"@typescript-eslint/parser": "^8.0.0",
|
|
50
|
-
"@vitest/coverage-v8": "^4.1.2",
|
|
51
|
-
"@vitest/ui": "^4.1.2",
|
|
52
|
-
"eslint": "^9.0.0",
|
|
53
|
-
"happy-dom": "^20.0.0",
|
|
54
|
-
"prettier": "^3.2.4",
|
|
55
|
-
"typescript": "^5.7.0",
|
|
56
|
-
"vite": "^8.0.3",
|
|
57
|
-
"vite-plugin-dts": "^4.5.0",
|
|
58
|
-
"vitest": "^4.1.2"
|
|
2
|
+
"name": "@inertiaui/vanilla",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"author": "Pascal Baljet <pascal@protone.media>",
|
|
5
|
+
"private": false,
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
59
18
|
}
|
|
60
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/inertiaui/vanilla"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"dialog",
|
|
26
|
+
"focus-trap",
|
|
27
|
+
"scroll-lock",
|
|
28
|
+
"aria-hidden",
|
|
29
|
+
"animation",
|
|
30
|
+
"web-animations-api",
|
|
31
|
+
"accessibility",
|
|
32
|
+
"a11y",
|
|
33
|
+
"vanilla-js",
|
|
34
|
+
"typescript"
|
|
35
|
+
],
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@playwright/test": "^1.58.2",
|
|
38
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
39
|
+
"@vitest/ui": "^4.1.2",
|
|
40
|
+
"happy-dom": "^20.0.0",
|
|
41
|
+
"oxfmt": "^0.52.0",
|
|
42
|
+
"oxlint": "^1.67.0",
|
|
43
|
+
"typescript": "^5.7.0",
|
|
44
|
+
"vite": "^8.0.3",
|
|
45
|
+
"vite-plugin-dts": "^4.5.0",
|
|
46
|
+
"vitest": "^4.1.2"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"dev": "vite build --watch",
|
|
50
|
+
"build": "vite build",
|
|
51
|
+
"lint": "oxlint --fix",
|
|
52
|
+
"format": "oxfmt",
|
|
53
|
+
"format:check": "oxfmt --check",
|
|
54
|
+
"test": "vitest",
|
|
55
|
+
"test:e2e": "playwright test"
|
|
56
|
+
}
|
|
57
|
+
}
|