@primer/behaviors 1.9.1-rc.5011fc8 → 1.9.1-rc.69df32c
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
|
@@ -28,6 +28,7 @@ export type FocusZoneSettings = IterateFocusableElements & {
|
|
|
28
28
|
focusInStrategy?: 'first' | 'closest' | 'previous' | 'initial' | ((previousFocusedElement: Element) => HTMLElement | undefined);
|
|
29
29
|
preventScroll?: boolean;
|
|
30
30
|
ignoreHoverEvents?: boolean;
|
|
31
|
+
focusPrependedElements?: boolean;
|
|
31
32
|
};
|
|
32
33
|
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
|
33
34
|
export declare const activeDescendantActivatedDirectly = "activated-directly";
|
package/dist/cjs/focus-zone.js
CHANGED
|
@@ -131,7 +131,7 @@ const activeDescendantActivatedDirectly = 'activated-directly';
|
|
|
131
131
|
const activeDescendantActivatedIndirectly = 'activated-indirectly';
|
|
132
132
|
const hasActiveDescendantAttribute = 'data-has-active-descendant';
|
|
133
133
|
function focusZone(container, settings) {
|
|
134
|
-
var _a, _b, _c, _d, _e, _f;
|
|
134
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
135
135
|
const focusableElements = new indexedSet.IndexedSet();
|
|
136
136
|
const savedTabIndex = new WeakMap();
|
|
137
137
|
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;
|
|
@@ -140,8 +140,10 @@ function focusZone(container, settings) {
|
|
|
140
140
|
const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
|
|
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
|
+
const focusPrependedElements = (_e = settings === null || settings === void 0 ? void 0 : settings.focusPrependedElements) !== null && _e !== void 0 ? _e : false;
|
|
143
144
|
let currentFocusedElement;
|
|
144
|
-
|
|
145
|
+
let wasDirectlyActivated = false;
|
|
146
|
+
const preventScroll = (_f = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _f !== void 0 ? _f : false;
|
|
145
147
|
const preventInitialFocus = focusInStrategy === 'initial' && (settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl);
|
|
146
148
|
function getFirstFocusableElement() {
|
|
147
149
|
return focusableElements.get(0);
|
|
@@ -152,6 +154,7 @@ function focusZone(container, settings) {
|
|
|
152
154
|
function updateFocusedElement(to, directlyActivated = false) {
|
|
153
155
|
const from = currentFocusedElement;
|
|
154
156
|
currentFocusedElement = to;
|
|
157
|
+
wasDirectlyActivated = directlyActivated;
|
|
155
158
|
if (activeDescendantControl) {
|
|
156
159
|
if (to && isActiveDescendantInputFocused()) {
|
|
157
160
|
setActiveDescendant(from, to, directlyActivated);
|
|
@@ -202,14 +205,16 @@ function focusZone(container, settings) {
|
|
|
202
205
|
if (filteredElements.length === 0) {
|
|
203
206
|
return;
|
|
204
207
|
}
|
|
205
|
-
|
|
208
|
+
const insertionIndex = findInsertionIndex(filteredElements);
|
|
209
|
+
focusableElements.insertAt(insertionIndex, ...filteredElements);
|
|
206
210
|
for (const element of filteredElements) {
|
|
207
211
|
if (!savedTabIndex.has(element)) {
|
|
208
212
|
savedTabIndex.set(element, element.getAttribute('tabindex'));
|
|
209
213
|
}
|
|
210
214
|
element.setAttribute('tabindex', '-1');
|
|
211
215
|
}
|
|
212
|
-
|
|
216
|
+
const shouldFocusPrepended = focusPrependedElements && insertionIndex === 0 && !wasDirectlyActivated;
|
|
217
|
+
if (!preventInitialFocus && (!currentFocusedElement || shouldFocusPrepended)) {
|
|
213
218
|
updateFocusedElement(getFirstFocusableElement());
|
|
214
219
|
}
|
|
215
220
|
}
|
|
@@ -327,7 +332,7 @@ function focusZone(container, settings) {
|
|
|
327
332
|
attributeOldValue: true,
|
|
328
333
|
});
|
|
329
334
|
const controller = new AbortController();
|
|
330
|
-
const signal = (
|
|
335
|
+
const signal = (_g = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _g !== void 0 ? _g : controller.signal;
|
|
331
336
|
signal.addEventListener('abort', () => {
|
|
332
337
|
observer.disconnect();
|
|
333
338
|
endFocusManagement(...focusableElements);
|
package/dist/esm/focus-zone.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export type FocusZoneSettings = IterateFocusableElements & {
|
|
|
28
28
|
focusInStrategy?: 'first' | 'closest' | 'previous' | 'initial' | ((previousFocusedElement: Element) => HTMLElement | undefined);
|
|
29
29
|
preventScroll?: boolean;
|
|
30
30
|
ignoreHoverEvents?: boolean;
|
|
31
|
+
focusPrependedElements?: boolean;
|
|
31
32
|
};
|
|
32
33
|
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
|
33
34
|
export declare const activeDescendantActivatedDirectly = "activated-directly";
|
package/dist/esm/focus-zone.mjs
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, _f;
|
|
132
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
133
133
|
const focusableElements = new IndexedSet();
|
|
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) ? FocusKeys.ArrowAll : FocusKeys.ArrowVertical) | FocusKeys.HomeAndEnd;
|
|
@@ -138,8 +138,10 @@ function focusZone(container, settings) {
|
|
|
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
140
|
const ignoreHoverEvents = (_d = settings === null || settings === void 0 ? void 0 : settings.ignoreHoverEvents) !== null && _d !== void 0 ? _d : false;
|
|
141
|
+
const focusPrependedElements = (_e = settings === null || settings === void 0 ? void 0 : settings.focusPrependedElements) !== null && _e !== void 0 ? _e : false;
|
|
141
142
|
let currentFocusedElement;
|
|
142
|
-
|
|
143
|
+
let wasDirectlyActivated = false;
|
|
144
|
+
const preventScroll = (_f = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _f !== void 0 ? _f : false;
|
|
143
145
|
const preventInitialFocus = focusInStrategy === 'initial' && (settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl);
|
|
144
146
|
function getFirstFocusableElement() {
|
|
145
147
|
return focusableElements.get(0);
|
|
@@ -150,6 +152,7 @@ function focusZone(container, settings) {
|
|
|
150
152
|
function updateFocusedElement(to, directlyActivated = false) {
|
|
151
153
|
const from = currentFocusedElement;
|
|
152
154
|
currentFocusedElement = to;
|
|
155
|
+
wasDirectlyActivated = directlyActivated;
|
|
153
156
|
if (activeDescendantControl) {
|
|
154
157
|
if (to && isActiveDescendantInputFocused()) {
|
|
155
158
|
setActiveDescendant(from, to, directlyActivated);
|
|
@@ -200,14 +203,16 @@ function focusZone(container, settings) {
|
|
|
200
203
|
if (filteredElements.length === 0) {
|
|
201
204
|
return;
|
|
202
205
|
}
|
|
203
|
-
|
|
206
|
+
const insertionIndex = findInsertionIndex(filteredElements);
|
|
207
|
+
focusableElements.insertAt(insertionIndex, ...filteredElements);
|
|
204
208
|
for (const element of filteredElements) {
|
|
205
209
|
if (!savedTabIndex.has(element)) {
|
|
206
210
|
savedTabIndex.set(element, element.getAttribute('tabindex'));
|
|
207
211
|
}
|
|
208
212
|
element.setAttribute('tabindex', '-1');
|
|
209
213
|
}
|
|
210
|
-
|
|
214
|
+
const shouldFocusPrepended = focusPrependedElements && insertionIndex === 0 && !wasDirectlyActivated;
|
|
215
|
+
if (!preventInitialFocus && (!currentFocusedElement || shouldFocusPrepended)) {
|
|
211
216
|
updateFocusedElement(getFirstFocusableElement());
|
|
212
217
|
}
|
|
213
218
|
}
|
|
@@ -325,7 +330,7 @@ function focusZone(container, settings) {
|
|
|
325
330
|
attributeOldValue: true,
|
|
326
331
|
});
|
|
327
332
|
const controller = new AbortController();
|
|
328
|
-
const signal = (
|
|
333
|
+
const signal = (_g = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _g !== void 0 ? _g : controller.signal;
|
|
329
334
|
signal.addEventListener('abort', () => {
|
|
330
335
|
observer.disconnect();
|
|
331
336
|
endFocusManagement(...focusableElements);
|