@primer/behaviors 1.9.2 → 1.10.0

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