@primer/behaviors 0.0.0-20251203212431 → 0.0.0-20251204200358
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 +2 -1
- package/dist/cjs/focus-zone.js +19 -19
- package/dist/esm/focus-zone.d.ts +2 -1
- package/dist/esm/focus-zone.mjs +19 -19
- package/package.json +1 -1
package/dist/cjs/focus-zone.d.ts
CHANGED
|
@@ -25,8 +25,9 @@ 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' |
|
|
28
|
+
focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
|
|
29
29
|
preventScroll?: boolean;
|
|
30
|
+
ignoreHoverEvents?: boolean;
|
|
30
31
|
};
|
|
31
32
|
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
|
32
33
|
export declare const activeDescendantActivatedDirectly = "activated-directly";
|
package/dist/cjs/focus-zone.js
CHANGED
|
@@ -129,7 +129,7 @@ const activeDescendantActivatedDirectly = 'activated-directly';
|
|
|
129
129
|
const activeDescendantActivatedIndirectly = 'activated-indirectly';
|
|
130
130
|
const hasActiveDescendantAttribute = 'data-has-active-descendant';
|
|
131
131
|
function focusZone(container, settings) {
|
|
132
|
-
var _a, _b, _c, _d, _e;
|
|
132
|
+
var _a, _b, _c, _d, _e, _f;
|
|
133
133
|
const focusableElements = [];
|
|
134
134
|
const savedTabIndex = new WeakMap();
|
|
135
135
|
const bindKeys = (_a = settings === null || settings === void 0 ? void 0 : settings.bindKeys) !== null && _a !== void 0 ? _a : ((settings === null || settings === void 0 ? void 0 : settings.getNextFocusable) ? exports.FocusKeys.ArrowAll : exports.FocusKeys.ArrowVertical) | exports.FocusKeys.HomeAndEnd;
|
|
@@ -137,9 +137,9 @@ function focusZone(container, settings) {
|
|
|
137
137
|
const focusInStrategy = (_c = settings === null || settings === void 0 ? void 0 : settings.focusInStrategy) !== null && _c !== void 0 ? _c : 'previous';
|
|
138
138
|
const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
|
|
139
139
|
const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
|
|
140
|
+
const ignoreHoverEvents = (_d = settings === null || settings === void 0 ? void 0 : settings.ignoreHoverEvents) !== null && _d !== void 0 ? _d : false;
|
|
140
141
|
let currentFocusedElement;
|
|
141
|
-
const preventScroll = (
|
|
142
|
-
const preventInitialFocus = focusInStrategy === 'initial' && (settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl);
|
|
142
|
+
const preventScroll = (_e = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _e !== void 0 ? _e : false;
|
|
143
143
|
function getFirstFocusableElement() {
|
|
144
144
|
return focusableElements[0];
|
|
145
145
|
}
|
|
@@ -203,7 +203,7 @@ function focusZone(container, settings) {
|
|
|
203
203
|
}
|
|
204
204
|
element.setAttribute('tabindex', '-1');
|
|
205
205
|
}
|
|
206
|
-
if (!currentFocusedElement
|
|
206
|
+
if (!currentFocusedElement) {
|
|
207
207
|
updateFocusedElement(getFirstFocusableElement());
|
|
208
208
|
}
|
|
209
209
|
}
|
|
@@ -257,8 +257,7 @@ function focusZone(container, settings) {
|
|
|
257
257
|
};
|
|
258
258
|
beginFocusManagement(...iterateFocusableElements.iterateFocusableElements(container, iterateFocusableElementsOptions));
|
|
259
259
|
const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
|
|
260
|
-
|
|
261
|
-
updateFocusedElement(initialElement);
|
|
260
|
+
updateFocusedElement(initialElement);
|
|
262
261
|
const observer = new MutationObserver(mutations => {
|
|
263
262
|
for (const mutation of mutations) {
|
|
264
263
|
for (const removedNode of mutation.removedNodes) {
|
|
@@ -292,7 +291,7 @@ function focusZone(container, settings) {
|
|
|
292
291
|
attributeOldValue: true,
|
|
293
292
|
});
|
|
294
293
|
const controller = new AbortController();
|
|
295
|
-
const signal = (
|
|
294
|
+
const signal = (_f = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _f !== void 0 ? _f : controller.signal;
|
|
296
295
|
signal.addEventListener('abort', () => {
|
|
297
296
|
endFocusManagement(...focusableElements);
|
|
298
297
|
});
|
|
@@ -309,19 +308,20 @@ function focusZone(container, settings) {
|
|
|
309
308
|
updateFocusedElement(event.target);
|
|
310
309
|
}
|
|
311
310
|
}, { signal });
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
311
|
+
if (!ignoreHoverEvents) {
|
|
312
|
+
container.addEventListener('mousemove', ({ target }) => {
|
|
313
|
+
if (!(target instanceof Node)) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const focusableElement = focusableElements.find(element => element.contains(target));
|
|
317
|
+
if (focusableElement) {
|
|
318
|
+
updateFocusedElement(focusableElement);
|
|
319
|
+
}
|
|
320
|
+
}, { signal, capture: true });
|
|
321
|
+
}
|
|
321
322
|
activeDescendantControl.addEventListener('focusin', () => {
|
|
322
323
|
if (!currentFocusedElement) {
|
|
323
|
-
|
|
324
|
-
updateFocusedElement(getFirstFocusableElement());
|
|
324
|
+
updateFocusedElement(getFirstFocusableElement());
|
|
325
325
|
}
|
|
326
326
|
else {
|
|
327
327
|
setActiveDescendant(undefined, currentFocusedElement);
|
|
@@ -389,7 +389,7 @@ function focusZone(container, settings) {
|
|
|
389
389
|
}
|
|
390
390
|
function getCurrentFocusedIndex() {
|
|
391
391
|
if (!currentFocusedElement) {
|
|
392
|
-
return
|
|
392
|
+
return 0;
|
|
393
393
|
}
|
|
394
394
|
const focusedIndex = focusableElements.indexOf(currentFocusedElement);
|
|
395
395
|
const fallbackIndex = currentFocusedElement === container ? -1 : 0;
|
package/dist/esm/focus-zone.d.ts
CHANGED
|
@@ -25,8 +25,9 @@ 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' |
|
|
28
|
+
focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
|
|
29
29
|
preventScroll?: boolean;
|
|
30
|
+
ignoreHoverEvents?: boolean;
|
|
30
31
|
};
|
|
31
32
|
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
|
32
33
|
export declare const activeDescendantActivatedDirectly = "activated-directly";
|
package/dist/esm/focus-zone.mjs
CHANGED
|
@@ -127,7 +127,7 @@ const activeDescendantActivatedDirectly = 'activated-directly';
|
|
|
127
127
|
const activeDescendantActivatedIndirectly = 'activated-indirectly';
|
|
128
128
|
const hasActiveDescendantAttribute = 'data-has-active-descendant';
|
|
129
129
|
function focusZone(container, settings) {
|
|
130
|
-
var _a, _b, _c, _d, _e;
|
|
130
|
+
var _a, _b, _c, _d, _e, _f;
|
|
131
131
|
const focusableElements = [];
|
|
132
132
|
const savedTabIndex = new WeakMap();
|
|
133
133
|
const bindKeys = (_a = settings === null || settings === void 0 ? void 0 : settings.bindKeys) !== null && _a !== void 0 ? _a : ((settings === null || settings === void 0 ? void 0 : settings.getNextFocusable) ? FocusKeys.ArrowAll : FocusKeys.ArrowVertical) | FocusKeys.HomeAndEnd;
|
|
@@ -135,9 +135,9 @@ function focusZone(container, settings) {
|
|
|
135
135
|
const focusInStrategy = (_c = settings === null || settings === void 0 ? void 0 : settings.focusInStrategy) !== null && _c !== void 0 ? _c : 'previous';
|
|
136
136
|
const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
|
|
137
137
|
const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
|
|
138
|
+
const ignoreHoverEvents = (_d = settings === null || settings === void 0 ? void 0 : settings.ignoreHoverEvents) !== null && _d !== void 0 ? _d : false;
|
|
138
139
|
let currentFocusedElement;
|
|
139
|
-
const preventScroll = (
|
|
140
|
-
const preventInitialFocus = focusInStrategy === 'initial' && (settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl);
|
|
140
|
+
const preventScroll = (_e = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _e !== void 0 ? _e : false;
|
|
141
141
|
function getFirstFocusableElement() {
|
|
142
142
|
return focusableElements[0];
|
|
143
143
|
}
|
|
@@ -201,7 +201,7 @@ function focusZone(container, settings) {
|
|
|
201
201
|
}
|
|
202
202
|
element.setAttribute('tabindex', '-1');
|
|
203
203
|
}
|
|
204
|
-
if (!currentFocusedElement
|
|
204
|
+
if (!currentFocusedElement) {
|
|
205
205
|
updateFocusedElement(getFirstFocusableElement());
|
|
206
206
|
}
|
|
207
207
|
}
|
|
@@ -255,8 +255,7 @@ function focusZone(container, settings) {
|
|
|
255
255
|
};
|
|
256
256
|
beginFocusManagement(...iterateFocusableElements(container, iterateFocusableElementsOptions));
|
|
257
257
|
const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
|
|
258
|
-
|
|
259
|
-
updateFocusedElement(initialElement);
|
|
258
|
+
updateFocusedElement(initialElement);
|
|
260
259
|
const observer = new MutationObserver(mutations => {
|
|
261
260
|
for (const mutation of mutations) {
|
|
262
261
|
for (const removedNode of mutation.removedNodes) {
|
|
@@ -290,7 +289,7 @@ function focusZone(container, settings) {
|
|
|
290
289
|
attributeOldValue: true,
|
|
291
290
|
});
|
|
292
291
|
const controller = new AbortController();
|
|
293
|
-
const signal = (
|
|
292
|
+
const signal = (_f = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _f !== void 0 ? _f : controller.signal;
|
|
294
293
|
signal.addEventListener('abort', () => {
|
|
295
294
|
endFocusManagement(...focusableElements);
|
|
296
295
|
});
|
|
@@ -307,19 +306,20 @@ function focusZone(container, settings) {
|
|
|
307
306
|
updateFocusedElement(event.target);
|
|
308
307
|
}
|
|
309
308
|
}, { signal });
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
309
|
+
if (!ignoreHoverEvents) {
|
|
310
|
+
container.addEventListener('mousemove', ({ target }) => {
|
|
311
|
+
if (!(target instanceof Node)) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const focusableElement = focusableElements.find(element => element.contains(target));
|
|
315
|
+
if (focusableElement) {
|
|
316
|
+
updateFocusedElement(focusableElement);
|
|
317
|
+
}
|
|
318
|
+
}, { signal, capture: true });
|
|
319
|
+
}
|
|
319
320
|
activeDescendantControl.addEventListener('focusin', () => {
|
|
320
321
|
if (!currentFocusedElement) {
|
|
321
|
-
|
|
322
|
-
updateFocusedElement(getFirstFocusableElement());
|
|
322
|
+
updateFocusedElement(getFirstFocusableElement());
|
|
323
323
|
}
|
|
324
324
|
else {
|
|
325
325
|
setActiveDescendant(undefined, currentFocusedElement);
|
|
@@ -387,7 +387,7 @@ function focusZone(container, settings) {
|
|
|
387
387
|
}
|
|
388
388
|
function getCurrentFocusedIndex() {
|
|
389
389
|
if (!currentFocusedElement) {
|
|
390
|
-
return
|
|
390
|
+
return 0;
|
|
391
391
|
}
|
|
392
392
|
const focusedIndex = focusableElements.indexOf(currentFocusedElement);
|
|
393
393
|
const fallbackIndex = currentFocusedElement === container ? -1 : 0;
|