@primer/behaviors 0.0.0-20260109180928 → 0.0.0-20260113010421

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.
@@ -214,25 +214,10 @@ function focusZone(container, settings) {
214
214
  element.setAttribute('tabindex', '-1');
215
215
  }
216
216
  const shouldFocusPrepended = focusPrependedElements && insertionIndex === 0 && !wasDirectlyActivated;
217
- if (!preventInitialFocus && shouldFocusPrepended) {
218
- reinitializeWithFreshElements();
219
- }
220
- else if (!preventInitialFocus && !currentFocusedElement) {
217
+ if (!preventInitialFocus && (!currentFocusedElement || shouldFocusPrepended)) {
221
218
  updateFocusedElement(getFirstFocusableElement());
222
219
  }
223
220
  }
224
- function reinitializeWithFreshElements() {
225
- const freshElements = [...iterateFocusableElements.iterateFocusableElements(container, iterateFocusableElementsOptions)];
226
- focusableElements.clear();
227
- focusableElements.insertAt(0, ...freshElements);
228
- for (const element of freshElements) {
229
- if (!savedTabIndex.has(element)) {
230
- savedTabIndex.set(element, element.getAttribute('tabindex'));
231
- }
232
- element.setAttribute('tabindex', '-1');
233
- }
234
- updateFocusedElement(getFirstFocusableElement());
235
- }
236
221
  function findInsertionIndex(elementsToInsert) {
237
222
  const firstElementToInsert = elementsToInsert[0];
238
223
  if (focusableElements.size === 0)
@@ -333,12 +318,7 @@ function focusZone(container, settings) {
333
318
  }
334
319
  }
335
320
  if (toAdd.length > 0) {
336
- if (focusPrependedElements) {
337
- reinitializeWithFreshElements();
338
- }
339
- else {
340
- beginFocusManagement(...toAdd);
341
- }
321
+ beginFocusManagement(...toAdd);
342
322
  }
343
323
  }
344
324
  if (attributeAdditions.size > 0) {
@@ -212,25 +212,10 @@ function focusZone(container, settings) {
212
212
  element.setAttribute('tabindex', '-1');
213
213
  }
214
214
  const shouldFocusPrepended = focusPrependedElements && insertionIndex === 0 && !wasDirectlyActivated;
215
- if (!preventInitialFocus && shouldFocusPrepended) {
216
- reinitializeWithFreshElements();
217
- }
218
- else if (!preventInitialFocus && !currentFocusedElement) {
215
+ if (!preventInitialFocus && (!currentFocusedElement || shouldFocusPrepended)) {
219
216
  updateFocusedElement(getFirstFocusableElement());
220
217
  }
221
218
  }
222
- function reinitializeWithFreshElements() {
223
- const freshElements = [...iterateFocusableElements(container, iterateFocusableElementsOptions)];
224
- focusableElements.clear();
225
- focusableElements.insertAt(0, ...freshElements);
226
- for (const element of freshElements) {
227
- if (!savedTabIndex.has(element)) {
228
- savedTabIndex.set(element, element.getAttribute('tabindex'));
229
- }
230
- element.setAttribute('tabindex', '-1');
231
- }
232
- updateFocusedElement(getFirstFocusableElement());
233
- }
234
219
  function findInsertionIndex(elementsToInsert) {
235
220
  const firstElementToInsert = elementsToInsert[0];
236
221
  if (focusableElements.size === 0)
@@ -331,12 +316,7 @@ function focusZone(container, settings) {
331
316
  }
332
317
  }
333
318
  if (toAdd.length > 0) {
334
- if (focusPrependedElements) {
335
- reinitializeWithFreshElements();
336
- }
337
- else {
338
- beginFocusManagement(...toAdd);
339
- }
319
+ beginFocusManagement(...toAdd);
340
320
  }
341
321
  }
342
322
  if (attributeAdditions.size > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "0.0.0-20260109180928",
3
+ "version": "0.0.0-20260113010421",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "type": "commonjs",
6
6
  "main": "dist/cjs/index.js",