motion-dom 11.16.0 → 11.16.1

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/dist/cjs/index.js CHANGED
@@ -377,6 +377,25 @@ function hover(elementOrSelector, onHoverStart, options = {}) {
377
377
  return cancel;
378
378
  }
379
379
 
380
+ /**
381
+ * Recursively traverse up the tree to check whether the provided child node
382
+ * is the parent or a descendant of it.
383
+ *
384
+ * @param parent - Element to find
385
+ * @param child - Element to test against parent
386
+ */
387
+ const isNodeOrChild = (parent, child) => {
388
+ if (!child) {
389
+ return false;
390
+ }
391
+ else if (parent === child) {
392
+ return true;
393
+ }
394
+ else {
395
+ return isNodeOrChild(parent, child.parentElement);
396
+ }
397
+ };
398
+
380
399
  const isPrimaryPointer = (event) => {
381
400
  if (event.pointerType === "mouse") {
382
401
  return typeof event.button !== "number" || event.button <= 0;
@@ -394,6 +413,17 @@ const isPrimaryPointer = (event) => {
394
413
  }
395
414
  };
396
415
 
416
+ const focusableElements = new Set([
417
+ "BUTTON",
418
+ "INPUT",
419
+ "SELECT",
420
+ "TEXTAREA",
421
+ "A",
422
+ ]);
423
+ function isElementKeyboardAccessible(element) {
424
+ return focusableElements.has(element.tagName) || element.tabIndex !== -1;
425
+ }
426
+
397
427
  const isPressing = new WeakSet();
398
428
 
399
429
  /**
@@ -431,36 +461,6 @@ const enableKeyboardPress = (focusEvent, eventOptions) => {
431
461
  element.addEventListener("blur", () => element.removeEventListener("keydown", handleKeydown), eventOptions);
432
462
  };
433
463
 
434
- const focusableElements = new Set([
435
- "BUTTON",
436
- "INPUT",
437
- "SELECT",
438
- "TEXTAREA",
439
- "A",
440
- ]);
441
- function isElementKeyboardAccessible(element) {
442
- return focusableElements.has(element.tagName) || element.tabIndex !== -1;
443
- }
444
-
445
- /**
446
- * Recursively traverse up the tree to check whether the provided child node
447
- * is the parent or a descendant of it.
448
- *
449
- * @param parent - Element to find
450
- * @param child - Element to test against parent
451
- */
452
- const isNodeOrChild = (parent, child) => {
453
- if (!child) {
454
- return false;
455
- }
456
- else if (parent === child) {
457
- return true;
458
- }
459
- else {
460
- return isNodeOrChild(parent, child.parentElement);
461
- }
462
- };
463
-
464
464
  /**
465
465
  * Filter out events that are not primary pointer events, or are triggering
466
466
  * while a Motion gesture is active.
@@ -517,7 +517,8 @@ function press(elementOrSelector, onPressStart, options = {}) {
517
517
  window.addEventListener("pointercancel", onPointerCancel, eventOptions);
518
518
  };
519
519
  elements.forEach((element) => {
520
- if (!isElementKeyboardAccessible(element)) {
520
+ if (!isElementKeyboardAccessible(element) &&
521
+ element.getAttribute("tabindex") === null) {
521
522
  element.tabIndex = 0;
522
523
  }
523
524
  const target = options.useGlobalTarget ? window : element;
@@ -1,9 +1,9 @@
1
1
  import { isDragActive } from '../drag/state/is-active.mjs';
2
+ import { isNodeOrChild } from '../utils/is-node-or-child.mjs';
2
3
  import { isPrimaryPointer } from '../utils/is-primary-pointer.mjs';
3
4
  import { setupGesture } from '../utils/setup.mjs';
4
- import { enableKeyboardPress } from './utils/keyboard.mjs';
5
5
  import { isElementKeyboardAccessible } from './utils/is-keyboard-accessible.mjs';
6
- import { isNodeOrChild } from '../utils/is-node-or-child.mjs';
6
+ import { enableKeyboardPress } from './utils/keyboard.mjs';
7
7
  import { isPressing } from './utils/state.mjs';
8
8
 
9
9
  /**
@@ -62,7 +62,8 @@ function press(elementOrSelector, onPressStart, options = {}) {
62
62
  window.addEventListener("pointercancel", onPointerCancel, eventOptions);
63
63
  };
64
64
  elements.forEach((element) => {
65
- if (!isElementKeyboardAccessible(element)) {
65
+ if (!isElementKeyboardAccessible(element) &&
66
+ element.getAttribute("tabindex") === null) {
66
67
  element.tabIndex = 0;
67
68
  }
68
69
  const target = options.useGlobalTarget ? window : element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion-dom",
3
- "version": "11.16.0",
3
+ "version": "11.16.1",
4
4
  "author": "Matt Perry",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/motiondivision/motion",
@@ -23,5 +23,5 @@
23
23
  "build": "yarn clean && tsc -p . && rollup -c",
24
24
  "dev": "concurrently -c blue,red -n tsc,rollup --kill-others \"tsc --watch -p . --preserveWatchOutput\" \"rollup --config --watch --no-watch.clearScreen\""
25
25
  },
26
- "gitHead": "0d6f15819d66d9e76f3b32bc79ceb001079da43e"
26
+ "gitHead": "d0d281ab97fe3ceef4d582d8da622faab907998d"
27
27
  }