@marianmeres/stuic 1.12.0 → 1.13.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.
@@ -1,19 +1,22 @@
1
1
  // copied from skeleton
2
- const defaults = { enabled: true, autoFocusFirst: false };
2
+ const defaults = { enabled: true, autoFocusFirst: true };
3
3
  // Action: Focus Trap
4
4
  export function focusTrap(node, options = {}) {
5
5
  let { enabled, autoFocusFirst } = { ...defaults, ...(options || {}) };
6
6
  const focusableSelectors = [
7
- 'a[href]',
8
- 'area[href]',
9
- 'details',
10
- 'iframe',
11
- 'button:not([disabled])',
12
- 'input:not([disabled])',
13
- 'select:not([disabled])',
14
- 'textarea:not([disabled])',
15
- '[contentEditable=true]',
16
- '[tabindex]',
7
+ '[contentEditable=true]:not([tabindex^="-"])',
8
+ //
9
+ 'button:not([disabled]):not([tabindex^="-"])',
10
+ 'input:not([disabled]):not([tabindex^="-"])',
11
+ 'select:not([disabled]):not([tabindex^="-"])',
12
+ 'textarea:not([disabled]):not([tabindex^="-"])',
13
+ //
14
+ 'a[href]:not([tabindex^="-"])',
15
+ 'area[href]:not([tabindex^="-"])',
16
+ 'details:not([tabindex^="-"])',
17
+ 'iframe:not([tabindex^="-"])',
18
+ //
19
+ '[tabindex]:not([tabindex^="-"])',
17
20
  ].join(',');
18
21
  let first;
19
22
  let last;
@@ -35,8 +38,8 @@ export function focusTrap(node, options = {}) {
35
38
  if (enabled === false)
36
39
  return;
37
40
  const focusable = [...node.querySelectorAll(focusableSelectors)]
38
- // i am unable to get the selectors right (still getting false positives),
39
- // but filtering manually works well
41
+ // in case I didn't get the selectors right, make sure to manually check as well...
42
+ // (negligible overhead, if any...)
40
43
  .filter((e) => {
41
44
  if (e.getAttribute('disabled') === '')
42
45
  return false;
@@ -44,10 +47,10 @@ export function focusTrap(node, options = {}) {
44
47
  return false;
45
48
  return true;
46
49
  })
47
- // sort by tabindex, so the first/last will work as expected
48
- .toSorted((e1, e2) => {
49
- let a = parseInt(e1.getAttribute('tabindex') || '0');
50
- let b = parseInt(e2.getAttribute('tabindex') || '0');
50
+ // important to sort by tabindex, so the first/last will work as expected
51
+ .sort((e1, e2) => {
52
+ const a = parseInt(e1.getAttribute('tabindex') || '0');
53
+ const b = parseInt(e2.getAttribute('tabindex') || '0');
51
54
  return a - b;
52
55
  });
53
56
  if (focusable.length) {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
- "build": "vite build && npm run package",
6
+ "build": "vite build && npm run package && node ./scripts/date.js",
7
7
  "build:watch": "fswatch -o src | xargs -n1 -I{} npm run build",
8
8
  "preview": "vite preview",
9
9
  "package": "svelte-kit sync && svelte-package && publint",