@primer/behaviors 0.0.0-20260105200348 → 0.0.0-20260106105613

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.
@@ -141,6 +141,7 @@ function focusZone(container, settings) {
141
141
  const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
142
142
  const ignoreHoverEvents = (_d = settings === null || settings === void 0 ? void 0 : settings.ignoreHoverEvents) !== null && _d !== void 0 ? _d : false;
143
143
  let currentFocusedElement;
144
+ let wasDirectlyActivated = false;
144
145
  const preventScroll = (_e = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _e !== void 0 ? _e : false;
145
146
  const preventInitialFocus = focusInStrategy === 'initial' && (settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl);
146
147
  function getFirstFocusableElement() {
@@ -152,6 +153,7 @@ function focusZone(container, settings) {
152
153
  function updateFocusedElement(to, directlyActivated = false) {
153
154
  const from = currentFocusedElement;
154
155
  currentFocusedElement = to;
156
+ wasDirectlyActivated = directlyActivated;
155
157
  if (activeDescendantControl) {
156
158
  if (to && isActiveDescendantInputFocused()) {
157
159
  setActiveDescendant(from, to, directlyActivated);
@@ -202,14 +204,15 @@ function focusZone(container, settings) {
202
204
  if (filteredElements.length === 0) {
203
205
  return;
204
206
  }
205
- focusableElements.insertAt(findInsertionIndex(filteredElements), ...filteredElements);
207
+ const insertionIndex = findInsertionIndex(filteredElements);
208
+ focusableElements.insertAt(insertionIndex, ...filteredElements);
206
209
  for (const element of filteredElements) {
207
210
  if (!savedTabIndex.has(element)) {
208
211
  savedTabIndex.set(element, element.getAttribute('tabindex'));
209
212
  }
210
213
  element.setAttribute('tabindex', '-1');
211
214
  }
212
- if (!currentFocusedElement && !preventInitialFocus) {
215
+ if (!preventInitialFocus && (!currentFocusedElement || (insertionIndex === 0 && !wasDirectlyActivated))) {
213
216
  updateFocusedElement(getFirstFocusableElement());
214
217
  }
215
218
  }
@@ -139,6 +139,7 @@ function focusZone(container, settings) {
139
139
  const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
140
140
  const ignoreHoverEvents = (_d = settings === null || settings === void 0 ? void 0 : settings.ignoreHoverEvents) !== null && _d !== void 0 ? _d : false;
141
141
  let currentFocusedElement;
142
+ let wasDirectlyActivated = false;
142
143
  const preventScroll = (_e = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _e !== void 0 ? _e : false;
143
144
  const preventInitialFocus = focusInStrategy === 'initial' && (settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl);
144
145
  function getFirstFocusableElement() {
@@ -150,6 +151,7 @@ function focusZone(container, settings) {
150
151
  function updateFocusedElement(to, directlyActivated = false) {
151
152
  const from = currentFocusedElement;
152
153
  currentFocusedElement = to;
154
+ wasDirectlyActivated = directlyActivated;
153
155
  if (activeDescendantControl) {
154
156
  if (to && isActiveDescendantInputFocused()) {
155
157
  setActiveDescendant(from, to, directlyActivated);
@@ -200,14 +202,15 @@ function focusZone(container, settings) {
200
202
  if (filteredElements.length === 0) {
201
203
  return;
202
204
  }
203
- focusableElements.insertAt(findInsertionIndex(filteredElements), ...filteredElements);
205
+ const insertionIndex = findInsertionIndex(filteredElements);
206
+ focusableElements.insertAt(insertionIndex, ...filteredElements);
204
207
  for (const element of filteredElements) {
205
208
  if (!savedTabIndex.has(element)) {
206
209
  savedTabIndex.set(element, element.getAttribute('tabindex'));
207
210
  }
208
211
  element.setAttribute('tabindex', '-1');
209
212
  }
210
- if (!currentFocusedElement && !preventInitialFocus) {
213
+ if (!preventInitialFocus && (!currentFocusedElement || (insertionIndex === 0 && !wasDirectlyActivated))) {
211
214
  updateFocusedElement(getFirstFocusableElement());
212
215
  }
213
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "0.0.0-20260105200348",
3
+ "version": "0.0.0-20260106105613",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "type": "commonjs",
6
6
  "main": "dist/cjs/index.js",