@primer/behaviors 0.0.0-20251204200358 → 0.0.0-20251205160246
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.d.ts
CHANGED
|
@@ -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
|
ignoreHoverEvents?: boolean;
|
|
31
31
|
};
|
package/dist/cjs/focus-zone.js
CHANGED
|
@@ -140,6 +140,7 @@ function focusZone(container, settings) {
|
|
|
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
142
|
const preventScroll = (_e = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _e !== void 0 ? _e : false;
|
|
143
|
+
const preventInitialFocus = focusInStrategy === 'initial' && (settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl);
|
|
143
144
|
function getFirstFocusableElement() {
|
|
144
145
|
return focusableElements[0];
|
|
145
146
|
}
|
|
@@ -203,7 +204,7 @@ function focusZone(container, settings) {
|
|
|
203
204
|
}
|
|
204
205
|
element.setAttribute('tabindex', '-1');
|
|
205
206
|
}
|
|
206
|
-
if (!currentFocusedElement) {
|
|
207
|
+
if (!currentFocusedElement && !preventInitialFocus) {
|
|
207
208
|
updateFocusedElement(getFirstFocusableElement());
|
|
208
209
|
}
|
|
209
210
|
}
|
|
@@ -257,7 +258,8 @@ function focusZone(container, settings) {
|
|
|
257
258
|
};
|
|
258
259
|
beginFocusManagement(...iterateFocusableElements.iterateFocusableElements(container, iterateFocusableElementsOptions));
|
|
259
260
|
const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
|
|
260
|
-
|
|
261
|
+
if (!preventInitialFocus)
|
|
262
|
+
updateFocusedElement(initialElement);
|
|
261
263
|
const observer = new MutationObserver(mutations => {
|
|
262
264
|
for (const mutation of mutations) {
|
|
263
265
|
for (const removedNode of mutation.removedNodes) {
|
|
@@ -321,7 +323,8 @@ function focusZone(container, settings) {
|
|
|
321
323
|
}
|
|
322
324
|
activeDescendantControl.addEventListener('focusin', () => {
|
|
323
325
|
if (!currentFocusedElement) {
|
|
324
|
-
|
|
326
|
+
if (!preventInitialFocus)
|
|
327
|
+
updateFocusedElement(getFirstFocusableElement());
|
|
325
328
|
}
|
|
326
329
|
else {
|
|
327
330
|
setActiveDescendant(undefined, currentFocusedElement);
|
|
@@ -389,7 +392,7 @@ function focusZone(container, settings) {
|
|
|
389
392
|
}
|
|
390
393
|
function getCurrentFocusedIndex() {
|
|
391
394
|
if (!currentFocusedElement) {
|
|
392
|
-
return 0;
|
|
395
|
+
return preventInitialFocus ? -1 : 0;
|
|
393
396
|
}
|
|
394
397
|
const focusedIndex = focusableElements.indexOf(currentFocusedElement);
|
|
395
398
|
const fallbackIndex = currentFocusedElement === container ? -1 : 0;
|
package/dist/esm/focus-zone.d.ts
CHANGED
|
@@ -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
|
ignoreHoverEvents?: boolean;
|
|
31
31
|
};
|
package/dist/esm/focus-zone.mjs
CHANGED
|
@@ -138,6 +138,7 @@ function focusZone(container, settings) {
|
|
|
138
138
|
const ignoreHoverEvents = (_d = settings === null || settings === void 0 ? void 0 : settings.ignoreHoverEvents) !== null && _d !== void 0 ? _d : false;
|
|
139
139
|
let currentFocusedElement;
|
|
140
140
|
const preventScroll = (_e = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _e !== void 0 ? _e : false;
|
|
141
|
+
const preventInitialFocus = focusInStrategy === 'initial' && (settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl);
|
|
141
142
|
function getFirstFocusableElement() {
|
|
142
143
|
return focusableElements[0];
|
|
143
144
|
}
|
|
@@ -201,7 +202,7 @@ function focusZone(container, settings) {
|
|
|
201
202
|
}
|
|
202
203
|
element.setAttribute('tabindex', '-1');
|
|
203
204
|
}
|
|
204
|
-
if (!currentFocusedElement) {
|
|
205
|
+
if (!currentFocusedElement && !preventInitialFocus) {
|
|
205
206
|
updateFocusedElement(getFirstFocusableElement());
|
|
206
207
|
}
|
|
207
208
|
}
|
|
@@ -255,7 +256,8 @@ function focusZone(container, settings) {
|
|
|
255
256
|
};
|
|
256
257
|
beginFocusManagement(...iterateFocusableElements(container, iterateFocusableElementsOptions));
|
|
257
258
|
const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
|
|
258
|
-
|
|
259
|
+
if (!preventInitialFocus)
|
|
260
|
+
updateFocusedElement(initialElement);
|
|
259
261
|
const observer = new MutationObserver(mutations => {
|
|
260
262
|
for (const mutation of mutations) {
|
|
261
263
|
for (const removedNode of mutation.removedNodes) {
|
|
@@ -319,7 +321,8 @@ function focusZone(container, settings) {
|
|
|
319
321
|
}
|
|
320
322
|
activeDescendantControl.addEventListener('focusin', () => {
|
|
321
323
|
if (!currentFocusedElement) {
|
|
322
|
-
|
|
324
|
+
if (!preventInitialFocus)
|
|
325
|
+
updateFocusedElement(getFirstFocusableElement());
|
|
323
326
|
}
|
|
324
327
|
else {
|
|
325
328
|
setActiveDescendant(undefined, currentFocusedElement);
|
|
@@ -387,7 +390,7 @@ function focusZone(container, settings) {
|
|
|
387
390
|
}
|
|
388
391
|
function getCurrentFocusedIndex() {
|
|
389
392
|
if (!currentFocusedElement) {
|
|
390
|
-
return 0;
|
|
393
|
+
return preventInitialFocus ? -1 : 0;
|
|
391
394
|
}
|
|
392
395
|
const focusedIndex = focusableElements.indexOf(currentFocusedElement);
|
|
393
396
|
const fallbackIndex = currentFocusedElement === container ? -1 : 0;
|