@primer/behaviors 0.0.0-20251202120914 → 0.0.0-20251203163923

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.
@@ -25,7 +25,7 @@ export type FocusZoneSettings = IterateFocusableElements & {
25
25
  abortSignal?: AbortSignal;
26
26
  activeDescendantControl?: HTMLElement;
27
27
  onActiveDescendantChanged?: (newActiveDescendant: HTMLElement | undefined, previousActiveDescendant: HTMLElement | undefined, directlyActivated: boolean) => void;
28
- focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
28
+ focusInStrategy?: 'first' | 'closest' | 'previous' | 'initial' | ((previousFocusedElement: Element) => HTMLElement | undefined);
29
29
  preventScroll?: boolean;
30
30
  };
31
31
  export declare const isActiveDescendantAttribute = "data-is-active-descendant";
@@ -202,7 +202,7 @@ function focusZone(container, settings) {
202
202
  }
203
203
  element.setAttribute('tabindex', '-1');
204
204
  }
205
- if (!currentFocusedElement) {
205
+ if (!currentFocusedElement && focusInStrategy !== 'initial') {
206
206
  updateFocusedElement(getFirstFocusableElement());
207
207
  }
208
208
  }
@@ -256,7 +256,8 @@ function focusZone(container, settings) {
256
256
  };
257
257
  beginFocusManagement(...iterateFocusableElements.iterateFocusableElements(container, iterateFocusableElementsOptions));
258
258
  const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
259
- updateFocusedElement(initialElement);
259
+ if (focusInStrategy !== 'initial')
260
+ updateFocusedElement(initialElement);
260
261
  const observer = new MutationObserver(mutations => {
261
262
  for (const mutation of mutations) {
262
263
  for (const removedNode of mutation.removedNodes) {
@@ -318,7 +319,8 @@ function focusZone(container, settings) {
318
319
  }, { signal, capture: true });
319
320
  activeDescendantControl.addEventListener('focusin', () => {
320
321
  if (!currentFocusedElement) {
321
- updateFocusedElement(getFirstFocusableElement());
322
+ if (focusInStrategy !== 'initial')
323
+ updateFocusedElement(getFirstFocusableElement());
322
324
  }
323
325
  else {
324
326
  setActiveDescendant(undefined, currentFocusedElement);
@@ -386,7 +388,7 @@ function focusZone(container, settings) {
386
388
  }
387
389
  function getCurrentFocusedIndex() {
388
390
  if (!currentFocusedElement) {
389
- return 0;
391
+ return focusInStrategy === 'initial' ? -1 : 0;
390
392
  }
391
393
  const focusedIndex = focusableElements.indexOf(currentFocusedElement);
392
394
  const fallbackIndex = currentFocusedElement === container ? -1 : 0;
@@ -25,7 +25,7 @@ export type FocusZoneSettings = IterateFocusableElements & {
25
25
  abortSignal?: AbortSignal;
26
26
  activeDescendantControl?: HTMLElement;
27
27
  onActiveDescendantChanged?: (newActiveDescendant: HTMLElement | undefined, previousActiveDescendant: HTMLElement | undefined, directlyActivated: boolean) => void;
28
- focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
28
+ focusInStrategy?: 'first' | 'closest' | 'previous' | 'initial' | ((previousFocusedElement: Element) => HTMLElement | undefined);
29
29
  preventScroll?: boolean;
30
30
  };
31
31
  export declare const isActiveDescendantAttribute = "data-is-active-descendant";
@@ -200,7 +200,7 @@ function focusZone(container, settings) {
200
200
  }
201
201
  element.setAttribute('tabindex', '-1');
202
202
  }
203
- if (!currentFocusedElement) {
203
+ if (!currentFocusedElement && focusInStrategy !== 'initial') {
204
204
  updateFocusedElement(getFirstFocusableElement());
205
205
  }
206
206
  }
@@ -254,7 +254,8 @@ function focusZone(container, settings) {
254
254
  };
255
255
  beginFocusManagement(...iterateFocusableElements(container, iterateFocusableElementsOptions));
256
256
  const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
257
- updateFocusedElement(initialElement);
257
+ if (focusInStrategy !== 'initial')
258
+ updateFocusedElement(initialElement);
258
259
  const observer = new MutationObserver(mutations => {
259
260
  for (const mutation of mutations) {
260
261
  for (const removedNode of mutation.removedNodes) {
@@ -316,7 +317,8 @@ function focusZone(container, settings) {
316
317
  }, { signal, capture: true });
317
318
  activeDescendantControl.addEventListener('focusin', () => {
318
319
  if (!currentFocusedElement) {
319
- updateFocusedElement(getFirstFocusableElement());
320
+ if (focusInStrategy !== 'initial')
321
+ updateFocusedElement(getFirstFocusableElement());
320
322
  }
321
323
  else {
322
324
  setActiveDescendant(undefined, currentFocusedElement);
@@ -384,7 +386,7 @@ function focusZone(container, settings) {
384
386
  }
385
387
  function getCurrentFocusedIndex() {
386
388
  if (!currentFocusedElement) {
387
- return 0;
389
+ return focusInStrategy === 'initial' ? -1 : 0;
388
390
  }
389
391
  const focusedIndex = focusableElements.indexOf(currentFocusedElement);
390
392
  const fallbackIndex = currentFocusedElement === container ? -1 : 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "0.0.0-20251202120914",
3
+ "version": "0.0.0-20251203163923",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "type": "commonjs",
6
6
  "main": "dist/cjs/index.js",