@primer/behaviors 0.0.0-20251214175049 → 0.0.0-20251215025613

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.
@@ -23,9 +23,10 @@ function observeFocusTrap(container, sentinels) {
23
23
  const observer = new MutationObserver(mutations => {
24
24
  for (const mutation of mutations) {
25
25
  if (mutation.type === 'childList' && mutation.addedNodes.length) {
26
- const sentinelChildren = Array.from(mutation.addedNodes).filter(e => e instanceof HTMLElement && e.classList.contains('sentinel') && e.tagName === 'SPAN');
27
- if (sentinelChildren.length) {
28
- return;
26
+ for (const node of mutation.addedNodes) {
27
+ if (node instanceof HTMLElement && node.tagName === 'SPAN' && node.classList.contains('sentinel')) {
28
+ return;
29
+ }
29
30
  }
30
31
  const firstChild = container.firstElementChild;
31
32
  const lastChild = container.lastElementChild;
@@ -348,6 +348,11 @@ function focusZone(container, settings) {
348
348
  if (!(target instanceof Node)) {
349
349
  return;
350
350
  }
351
+ const targetIndex = target instanceof HTMLElement ? focusableElements.indexOf(target) : -1;
352
+ if (targetIndex >= 0) {
353
+ updateFocusedElement(focusableElements[targetIndex]);
354
+ return;
355
+ }
351
356
  const focusableElement = focusableElements.find(element => element.contains(target));
352
357
  if (focusableElement) {
353
358
  updateFocusedElement(focusableElement);
@@ -21,9 +21,10 @@ function observeFocusTrap(container, sentinels) {
21
21
  const observer = new MutationObserver(mutations => {
22
22
  for (const mutation of mutations) {
23
23
  if (mutation.type === 'childList' && mutation.addedNodes.length) {
24
- const sentinelChildren = Array.from(mutation.addedNodes).filter(e => e instanceof HTMLElement && e.classList.contains('sentinel') && e.tagName === 'SPAN');
25
- if (sentinelChildren.length) {
26
- return;
24
+ for (const node of mutation.addedNodes) {
25
+ if (node instanceof HTMLElement && node.tagName === 'SPAN' && node.classList.contains('sentinel')) {
26
+ return;
27
+ }
27
28
  }
28
29
  const firstChild = container.firstElementChild;
29
30
  const lastChild = container.lastElementChild;
@@ -346,6 +346,11 @@ function focusZone(container, settings) {
346
346
  if (!(target instanceof Node)) {
347
347
  return;
348
348
  }
349
+ const targetIndex = target instanceof HTMLElement ? focusableElements.indexOf(target) : -1;
350
+ if (targetIndex >= 0) {
351
+ updateFocusedElement(focusableElements[targetIndex]);
352
+ return;
353
+ }
349
354
  const focusableElement = focusableElements.find(element => element.contains(target));
350
355
  if (focusableElement) {
351
356
  updateFocusedElement(focusableElement);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "0.0.0-20251214175049",
3
+ "version": "0.0.0-20251215025613",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "type": "commonjs",
6
6
  "main": "dist/cjs/index.js",