@primer/behaviors 0.0.0-20251203163923 → 0.0.0-20251203212431
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.
package/dist/cjs/focus-zone.js
CHANGED
|
@@ -139,6 +139,7 @@ function focusZone(container, settings) {
|
|
|
139
139
|
const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
|
|
140
140
|
let currentFocusedElement;
|
|
141
141
|
const preventScroll = (_d = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _d !== void 0 ? _d : false;
|
|
142
|
+
const preventInitialFocus = focusInStrategy === 'initial' && (settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl);
|
|
142
143
|
function getFirstFocusableElement() {
|
|
143
144
|
return focusableElements[0];
|
|
144
145
|
}
|
|
@@ -202,7 +203,7 @@ function focusZone(container, settings) {
|
|
|
202
203
|
}
|
|
203
204
|
element.setAttribute('tabindex', '-1');
|
|
204
205
|
}
|
|
205
|
-
if (!currentFocusedElement &&
|
|
206
|
+
if (!currentFocusedElement && !preventInitialFocus) {
|
|
206
207
|
updateFocusedElement(getFirstFocusableElement());
|
|
207
208
|
}
|
|
208
209
|
}
|
|
@@ -256,7 +257,7 @@ function focusZone(container, settings) {
|
|
|
256
257
|
};
|
|
257
258
|
beginFocusManagement(...iterateFocusableElements.iterateFocusableElements(container, iterateFocusableElementsOptions));
|
|
258
259
|
const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
|
|
259
|
-
if (
|
|
260
|
+
if (!preventInitialFocus)
|
|
260
261
|
updateFocusedElement(initialElement);
|
|
261
262
|
const observer = new MutationObserver(mutations => {
|
|
262
263
|
for (const mutation of mutations) {
|
|
@@ -319,7 +320,7 @@ function focusZone(container, settings) {
|
|
|
319
320
|
}, { signal, capture: true });
|
|
320
321
|
activeDescendantControl.addEventListener('focusin', () => {
|
|
321
322
|
if (!currentFocusedElement) {
|
|
322
|
-
if (
|
|
323
|
+
if (!preventInitialFocus)
|
|
323
324
|
updateFocusedElement(getFirstFocusableElement());
|
|
324
325
|
}
|
|
325
326
|
else {
|
|
@@ -388,7 +389,7 @@ function focusZone(container, settings) {
|
|
|
388
389
|
}
|
|
389
390
|
function getCurrentFocusedIndex() {
|
|
390
391
|
if (!currentFocusedElement) {
|
|
391
|
-
return
|
|
392
|
+
return preventInitialFocus ? -1 : 0;
|
|
392
393
|
}
|
|
393
394
|
const focusedIndex = focusableElements.indexOf(currentFocusedElement);
|
|
394
395
|
const fallbackIndex = currentFocusedElement === container ? -1 : 0;
|
package/dist/esm/focus-zone.mjs
CHANGED
|
@@ -137,6 +137,7 @@ function focusZone(container, settings) {
|
|
|
137
137
|
const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
|
|
138
138
|
let currentFocusedElement;
|
|
139
139
|
const preventScroll = (_d = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _d !== void 0 ? _d : false;
|
|
140
|
+
const preventInitialFocus = focusInStrategy === 'initial' && (settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl);
|
|
140
141
|
function getFirstFocusableElement() {
|
|
141
142
|
return focusableElements[0];
|
|
142
143
|
}
|
|
@@ -200,7 +201,7 @@ function focusZone(container, settings) {
|
|
|
200
201
|
}
|
|
201
202
|
element.setAttribute('tabindex', '-1');
|
|
202
203
|
}
|
|
203
|
-
if (!currentFocusedElement &&
|
|
204
|
+
if (!currentFocusedElement && !preventInitialFocus) {
|
|
204
205
|
updateFocusedElement(getFirstFocusableElement());
|
|
205
206
|
}
|
|
206
207
|
}
|
|
@@ -254,7 +255,7 @@ function focusZone(container, settings) {
|
|
|
254
255
|
};
|
|
255
256
|
beginFocusManagement(...iterateFocusableElements(container, iterateFocusableElementsOptions));
|
|
256
257
|
const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
|
|
257
|
-
if (
|
|
258
|
+
if (!preventInitialFocus)
|
|
258
259
|
updateFocusedElement(initialElement);
|
|
259
260
|
const observer = new MutationObserver(mutations => {
|
|
260
261
|
for (const mutation of mutations) {
|
|
@@ -317,7 +318,7 @@ function focusZone(container, settings) {
|
|
|
317
318
|
}, { signal, capture: true });
|
|
318
319
|
activeDescendantControl.addEventListener('focusin', () => {
|
|
319
320
|
if (!currentFocusedElement) {
|
|
320
|
-
if (
|
|
321
|
+
if (!preventInitialFocus)
|
|
321
322
|
updateFocusedElement(getFirstFocusableElement());
|
|
322
323
|
}
|
|
323
324
|
else {
|
|
@@ -386,7 +387,7 @@ function focusZone(container, settings) {
|
|
|
386
387
|
}
|
|
387
388
|
function getCurrentFocusedIndex() {
|
|
388
389
|
if (!currentFocusedElement) {
|
|
389
|
-
return
|
|
390
|
+
return preventInitialFocus ? -1 : 0;
|
|
390
391
|
}
|
|
391
392
|
const focusedIndex = focusableElements.indexOf(currentFocusedElement);
|
|
392
393
|
const fallbackIndex = currentFocusedElement === container ? -1 : 0;
|