@y14e/portal 1.4.5 → 1.4.6

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.
@@ -39,23 +39,23 @@ function containsComposed(container, element) {
39
39
  }
40
40
  return false;
41
41
  }
42
- function getComposedChildren(node) {
43
- if (node instanceof ShadowRoot) {
44
- return [...node.children];
42
+ function getComposedChildren(element) {
43
+ if (element instanceof ShadowRoot) {
44
+ return [...element.children];
45
45
  }
46
- if (!(node instanceof Element)) {
46
+ if (!(element instanceof Element)) {
47
47
  return [];
48
48
  }
49
- if (node instanceof HTMLSlotElement) {
50
- const assigned = node.assignedElements({ flatten: true });
49
+ if (element instanceof HTMLSlotElement) {
50
+ const assigned = element.assignedElements({ flatten: true });
51
51
  if (assigned.length) {
52
52
  return assigned;
53
53
  }
54
54
  }
55
- if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
56
- return [...node.shadowRoot.children];
55
+ if (element instanceof HTMLElement && element.shadowRoot?.mode === "open") {
56
+ return [...element.shadowRoot.children];
57
57
  }
58
- return [...node.children];
58
+ return [...element.children];
59
59
  }
60
60
  var FOCUSABLE_SELECTOR = ':is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])';
61
61
  var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
@@ -201,10 +201,8 @@ function isDisabledDeep(element) {
201
201
  if (isInert(current)) {
202
202
  return true;
203
203
  }
204
- if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
205
- if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
206
- return true;
207
- }
204
+ if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current) && !current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
205
+ return true;
208
206
  }
209
207
  current = current.parentNode;
210
208
  }
@@ -213,10 +211,7 @@ function isDisabledDeep(element) {
213
211
  function normalizeRadioGroup(elements) {
214
212
  let map = null;
215
213
  for (const element of elements) {
216
- if (!(element instanceof HTMLInputElement)) {
217
- continue;
218
- }
219
- if (!isUngroupedRadio(element)) {
214
+ if (!(element instanceof HTMLInputElement) || !isUngroupedRadio(element)) {
220
215
  continue;
221
216
  }
222
217
  if (!map) {
@@ -275,11 +270,11 @@ function getFocusables(container = document.body, options = {}) {
275
270
  match && isFocusable(match, { skipNegativeTabIndexCheck, skipVisibilityCheck }) && candidates.push(match);
276
271
  }
277
272
  } else {
278
- let traverse2 = function(node) {
279
- if (isFocusable(node, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(node)) {
280
- candidates.push(node);
273
+ let traverse2 = function(element) {
274
+ if (isFocusable(element, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(element)) {
275
+ candidates.push(element);
281
276
  }
282
- (!composed ? [...node.children] : getComposedChildren(node)).map(traverse2);
277
+ (!composed ? [...element.children] : getComposedChildren(element)).map(traverse2);
283
278
  };
284
279
  (!composed ? [...container.children] : getComposedChildren(container)).map(traverse2);
285
280
  }
@@ -426,6 +421,9 @@ var Portal = class {
426
421
  last ? focusElement(last) : this.#moveFocus("previous");
427
422
  };
428
423
  #onKeyDown = (event) => {
424
+ if (!(event instanceof KeyboardEvent)) {
425
+ return;
426
+ }
429
427
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
430
428
  if (key !== "Tab" || altKey || ctrlKey || metaKey) {
431
429
  return;
@@ -37,23 +37,23 @@ function containsComposed(container, element) {
37
37
  }
38
38
  return false;
39
39
  }
40
- function getComposedChildren(node) {
41
- if (node instanceof ShadowRoot) {
42
- return [...node.children];
40
+ function getComposedChildren(element) {
41
+ if (element instanceof ShadowRoot) {
42
+ return [...element.children];
43
43
  }
44
- if (!(node instanceof Element)) {
44
+ if (!(element instanceof Element)) {
45
45
  return [];
46
46
  }
47
- if (node instanceof HTMLSlotElement) {
48
- const assigned = node.assignedElements({ flatten: true });
47
+ if (element instanceof HTMLSlotElement) {
48
+ const assigned = element.assignedElements({ flatten: true });
49
49
  if (assigned.length) {
50
50
  return assigned;
51
51
  }
52
52
  }
53
- if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
54
- return [...node.shadowRoot.children];
53
+ if (element instanceof HTMLElement && element.shadowRoot?.mode === "open") {
54
+ return [...element.shadowRoot.children];
55
55
  }
56
- return [...node.children];
56
+ return [...element.children];
57
57
  }
58
58
  var FOCUSABLE_SELECTOR = ':is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])';
59
59
  var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
@@ -199,10 +199,8 @@ function isDisabledDeep(element) {
199
199
  if (isInert(current)) {
200
200
  return true;
201
201
  }
202
- if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
203
- if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
204
- return true;
205
- }
202
+ if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current) && !current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
203
+ return true;
206
204
  }
207
205
  current = current.parentNode;
208
206
  }
@@ -211,10 +209,7 @@ function isDisabledDeep(element) {
211
209
  function normalizeRadioGroup(elements) {
212
210
  let map = null;
213
211
  for (const element of elements) {
214
- if (!(element instanceof HTMLInputElement)) {
215
- continue;
216
- }
217
- if (!isUngroupedRadio(element)) {
212
+ if (!(element instanceof HTMLInputElement) || !isUngroupedRadio(element)) {
218
213
  continue;
219
214
  }
220
215
  if (!map) {
@@ -273,11 +268,11 @@ function getFocusables(container = document.body, options = {}) {
273
268
  match && isFocusable(match, { skipNegativeTabIndexCheck, skipVisibilityCheck }) && candidates.push(match);
274
269
  }
275
270
  } else {
276
- let traverse2 = function(node) {
277
- if (isFocusable(node, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(node)) {
278
- candidates.push(node);
271
+ let traverse2 = function(element) {
272
+ if (isFocusable(element, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(element)) {
273
+ candidates.push(element);
279
274
  }
280
- (!composed ? [...node.children] : getComposedChildren(node)).map(traverse2);
275
+ (!composed ? [...element.children] : getComposedChildren(element)).map(traverse2);
281
276
  };
282
277
  (!composed ? [...container.children] : getComposedChildren(container)).map(traverse2);
283
278
  }
@@ -424,6 +419,9 @@ var Portal = class {
424
419
  last ? focusElement(last) : this.#moveFocus("previous");
425
420
  };
426
421
  #onKeyDown = (event) => {
422
+ if (!(event instanceof KeyboardEvent)) {
423
+ return;
424
+ }
427
425
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
428
426
  if (key !== "Tab" || altKey || ctrlKey || metaKey) {
429
427
  return;
package/dist/index.cjs CHANGED
@@ -110,6 +110,9 @@ var Portal = class {
110
110
  last ? powerFocusable.focusElement(last) : this.#moveFocus("previous");
111
111
  };
112
112
  #onKeyDown = (event) => {
113
+ if (!(event instanceof KeyboardEvent)) {
114
+ return;
115
+ }
113
116
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
114
117
  if (key !== "Tab" || altKey || ctrlKey || metaKey) {
115
118
  return;
package/dist/index.js CHANGED
@@ -108,6 +108,9 @@ var Portal = class {
108
108
  last ? focusElement(last) : this.#moveFocus("previous");
109
109
  };
110
110
  #onKeyDown = (event) => {
111
+ if (!(event instanceof KeyboardEvent)) {
112
+ return;
113
+ }
111
114
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
112
115
  if (key !== "Tab" || altKey || ctrlKey || metaKey) {
113
116
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "description": "Lightweight DOM portal (teleport) utility with fully focus management",
5
5
  "keywords": [
6
6
  "a11y",
@@ -59,6 +59,6 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@y14e/attribute-utils": "^2.0.18",
62
- "power-focusable": "^4.5.6"
62
+ "power-focusable": "^4.5.9"
63
63
  }
64
64
  }