@primer/behaviors 0.0.0-20251203200457 → 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.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
|
};
|
|
31
31
|
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
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,8 @@ 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
|
-
|
|
260
|
+
if (!preventInitialFocus)
|
|
261
|
+
updateFocusedElement(initialElement);
|
|
260
262
|
const observer = new MutationObserver(mutations => {
|
|
261
263
|
for (const mutation of mutations) {
|
|
262
264
|
for (const removedNode of mutation.removedNodes) {
|
|
@@ -318,7 +320,8 @@ function focusZone(container, settings) {
|
|
|
318
320
|
}, { signal, capture: true });
|
|
319
321
|
activeDescendantControl.addEventListener('focusin', () => {
|
|
320
322
|
if (!currentFocusedElement) {
|
|
321
|
-
|
|
323
|
+
if (!preventInitialFocus)
|
|
324
|
+
updateFocusedElement(getFirstFocusableElement());
|
|
322
325
|
}
|
|
323
326
|
else {
|
|
324
327
|
setActiveDescendant(undefined, currentFocusedElement);
|
|
@@ -386,7 +389,7 @@ function focusZone(container, settings) {
|
|
|
386
389
|
}
|
|
387
390
|
function getCurrentFocusedIndex() {
|
|
388
391
|
if (!currentFocusedElement) {
|
|
389
|
-
return 0;
|
|
392
|
+
return preventInitialFocus ? -1 : 0;
|
|
390
393
|
}
|
|
391
394
|
const focusedIndex = focusableElements.indexOf(currentFocusedElement);
|
|
392
395
|
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
|
};
|
|
31
31
|
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
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,8 @@ function focusZone(container, settings) {
|
|
|
254
255
|
};
|
|
255
256
|
beginFocusManagement(...iterateFocusableElements(container, iterateFocusableElementsOptions));
|
|
256
257
|
const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
|
|
257
|
-
|
|
258
|
+
if (!preventInitialFocus)
|
|
259
|
+
updateFocusedElement(initialElement);
|
|
258
260
|
const observer = new MutationObserver(mutations => {
|
|
259
261
|
for (const mutation of mutations) {
|
|
260
262
|
for (const removedNode of mutation.removedNodes) {
|
|
@@ -316,7 +318,8 @@ function focusZone(container, settings) {
|
|
|
316
318
|
}, { signal, capture: true });
|
|
317
319
|
activeDescendantControl.addEventListener('focusin', () => {
|
|
318
320
|
if (!currentFocusedElement) {
|
|
319
|
-
|
|
321
|
+
if (!preventInitialFocus)
|
|
322
|
+
updateFocusedElement(getFirstFocusableElement());
|
|
320
323
|
}
|
|
321
324
|
else {
|
|
322
325
|
setActiveDescendant(undefined, currentFocusedElement);
|
|
@@ -384,7 +387,7 @@ function focusZone(container, settings) {
|
|
|
384
387
|
}
|
|
385
388
|
function getCurrentFocusedIndex() {
|
|
386
389
|
if (!currentFocusedElement) {
|
|
387
|
-
return 0;
|
|
390
|
+
return preventInitialFocus ? -1 : 0;
|
|
388
391
|
}
|
|
389
392
|
const focusedIndex = focusableElements.indexOf(currentFocusedElement);
|
|
390
393
|
const fallbackIndex = currentFocusedElement === container ? -1 : 0;
|