@primer/behaviors 0.0.0-202292020482 → 0.0.0-2022927173910
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 -2
- package/dist/cjs/focus-zone.js +11 -9
- package/dist/esm/focus-zone.d.ts +2 -2
- package/dist/esm/focus-zone.js +11 -9
- package/package.json +1 -1
package/dist/cjs/focus-zone.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare type Direction = 'previous' | 'next' | 'start' | 'end';
|
|
2
|
-
export declare type FocusMovementKeys = 'ArrowLeft' | 'ArrowDown' | 'ArrowUp' | 'ArrowRight' | 'h' | 'j' | 'k' | 'l' | 'a' | 's' | 'w' | 'd' | 'Tab' | 'Home' | 'End' | 'PageUp' | 'PageDown';
|
|
2
|
+
export declare type FocusMovementKeys = 'ArrowLeft' | 'ArrowDown' | 'ArrowUp' | 'ArrowRight' | 'h' | 'j' | 'k' | 'l' | 'a' | 's' | 'w' | 'd' | 'Tab' | 'Home' | 'End' | 'PageUp' | 'PageDown' | 'Backspace';
|
|
3
3
|
export declare enum FocusKeys {
|
|
4
4
|
ArrowHorizontal = 1,
|
|
5
5
|
ArrowVertical = 2,
|
|
@@ -10,6 +10,7 @@ export declare enum FocusKeys {
|
|
|
10
10
|
WS = 32,
|
|
11
11
|
AD = 64,
|
|
12
12
|
Tab = 128,
|
|
13
|
+
Backspace = 512,
|
|
13
14
|
ArrowAll = 3,
|
|
14
15
|
HJKL = 12,
|
|
15
16
|
WASD = 96,
|
|
@@ -24,7 +25,6 @@ export interface FocusZoneSettings {
|
|
|
24
25
|
activeDescendantControl?: HTMLElement;
|
|
25
26
|
onActiveDescendantChanged?: (newActiveDescendant: HTMLElement | undefined, previousActiveDescendant: HTMLElement | undefined, directlyActivated: boolean) => void;
|
|
26
27
|
focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
|
|
27
|
-
preventScroll?: boolean;
|
|
28
28
|
}
|
|
29
29
|
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
|
30
30
|
export declare const activeDescendantActivatedDirectly = "activated-directly";
|
package/dist/cjs/focus-zone.js
CHANGED
|
@@ -17,6 +17,7 @@ var FocusKeys;
|
|
|
17
17
|
FocusKeys[FocusKeys["WS"] = 32] = "WS";
|
|
18
18
|
FocusKeys[FocusKeys["AD"] = 64] = "AD";
|
|
19
19
|
FocusKeys[FocusKeys["Tab"] = 128] = "Tab";
|
|
20
|
+
FocusKeys[FocusKeys["Backspace"] = 512] = "Backspace";
|
|
20
21
|
FocusKeys[FocusKeys["ArrowAll"] = 3] = "ArrowAll";
|
|
21
22
|
FocusKeys[FocusKeys["HJKL"] = 12] = "HJKL";
|
|
22
23
|
FocusKeys[FocusKeys["WASD"] = 96] = "WASD";
|
|
@@ -39,7 +40,8 @@ const KEY_TO_BIT = {
|
|
|
39
40
|
Home: FocusKeys.HomeAndEnd,
|
|
40
41
|
End: FocusKeys.HomeAndEnd,
|
|
41
42
|
PageUp: FocusKeys.PageUpDown,
|
|
42
|
-
PageDown: FocusKeys.PageUpDown
|
|
43
|
+
PageDown: FocusKeys.PageUpDown,
|
|
44
|
+
Backspace: FocusKeys.Backspace
|
|
43
45
|
};
|
|
44
46
|
const KEY_TO_DIRECTION = {
|
|
45
47
|
ArrowLeft: 'previous',
|
|
@@ -58,7 +60,8 @@ const KEY_TO_DIRECTION = {
|
|
|
58
60
|
Home: 'start',
|
|
59
61
|
End: 'end',
|
|
60
62
|
PageUp: 'start',
|
|
61
|
-
PageDown: 'end'
|
|
63
|
+
PageDown: 'end',
|
|
64
|
+
Backspace: 'previous'
|
|
62
65
|
};
|
|
63
66
|
function getDirection(keyboardEvent) {
|
|
64
67
|
const direction = KEY_TO_DIRECTION[keyboardEvent.key];
|
|
@@ -124,7 +127,7 @@ exports.activeDescendantActivatedDirectly = 'activated-directly';
|
|
|
124
127
|
exports.activeDescendantActivatedIndirectly = 'activated-indirectly';
|
|
125
128
|
exports.hasActiveDescendantAttribute = 'data-has-active-descendant';
|
|
126
129
|
function focusZone(container, settings) {
|
|
127
|
-
var _a, _b, _c, _d
|
|
130
|
+
var _a, _b, _c, _d;
|
|
128
131
|
const focusableElements = [];
|
|
129
132
|
const savedTabIndex = new WeakMap();
|
|
130
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;
|
|
@@ -133,7 +136,6 @@ function focusZone(container, settings) {
|
|
|
133
136
|
const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
|
|
134
137
|
const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
|
|
135
138
|
let currentFocusedElement;
|
|
136
|
-
const preventScroll = (_d = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _d !== void 0 ? _d : false;
|
|
137
139
|
function getFirstFocusableElement() {
|
|
138
140
|
return focusableElements[0];
|
|
139
141
|
}
|
|
@@ -244,7 +246,7 @@ function focusZone(container, settings) {
|
|
|
244
246
|
childList: true
|
|
245
247
|
});
|
|
246
248
|
const controller = new AbortController();
|
|
247
|
-
const signal = (
|
|
249
|
+
const signal = (_d = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _d !== void 0 ? _d : controller.signal;
|
|
248
250
|
signal.addEventListener('abort', () => {
|
|
249
251
|
endFocusManagement(...focusableElements);
|
|
250
252
|
});
|
|
@@ -257,7 +259,7 @@ function focusZone(container, settings) {
|
|
|
257
259
|
if (activeDescendantControl) {
|
|
258
260
|
container.addEventListener('focusin', event => {
|
|
259
261
|
if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
|
|
260
|
-
activeDescendantControl.focus(
|
|
262
|
+
activeDescendantControl.focus();
|
|
261
263
|
updateFocusedElement(event.target);
|
|
262
264
|
}
|
|
263
265
|
});
|
|
@@ -301,7 +303,7 @@ function focusZone(container, settings) {
|
|
|
301
303
|
if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
|
|
302
304
|
const targetElementIndex = lastKeyboardFocusDirection === 'previous' ? focusableElements.length - 1 : 0;
|
|
303
305
|
const targetElement = focusableElements[targetElementIndex];
|
|
304
|
-
targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus(
|
|
306
|
+
targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus();
|
|
305
307
|
return;
|
|
306
308
|
}
|
|
307
309
|
else {
|
|
@@ -313,7 +315,7 @@ function focusZone(container, settings) {
|
|
|
313
315
|
const elementToFocus = focusInStrategy(event.relatedTarget);
|
|
314
316
|
const requestedFocusElementIndex = elementToFocus ? focusableElements.indexOf(elementToFocus) : -1;
|
|
315
317
|
if (requestedFocusElementIndex >= 0 && elementToFocus instanceof HTMLElement) {
|
|
316
|
-
elementToFocus.focus(
|
|
318
|
+
elementToFocus.focus();
|
|
317
319
|
return;
|
|
318
320
|
}
|
|
319
321
|
else {
|
|
@@ -398,7 +400,7 @@ function focusZone(container, settings) {
|
|
|
398
400
|
}
|
|
399
401
|
else if (nextElementToFocus) {
|
|
400
402
|
lastKeyboardFocusDirection = direction;
|
|
401
|
-
nextElementToFocus.focus(
|
|
403
|
+
nextElementToFocus.focus();
|
|
402
404
|
}
|
|
403
405
|
if (event.key !== 'Tab' || nextElementToFocus) {
|
|
404
406
|
event.preventDefault();
|
package/dist/esm/focus-zone.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare type Direction = 'previous' | 'next' | 'start' | 'end';
|
|
2
|
-
export declare type FocusMovementKeys = 'ArrowLeft' | 'ArrowDown' | 'ArrowUp' | 'ArrowRight' | 'h' | 'j' | 'k' | 'l' | 'a' | 's' | 'w' | 'd' | 'Tab' | 'Home' | 'End' | 'PageUp' | 'PageDown';
|
|
2
|
+
export declare type FocusMovementKeys = 'ArrowLeft' | 'ArrowDown' | 'ArrowUp' | 'ArrowRight' | 'h' | 'j' | 'k' | 'l' | 'a' | 's' | 'w' | 'd' | 'Tab' | 'Home' | 'End' | 'PageUp' | 'PageDown' | 'Backspace';
|
|
3
3
|
export declare enum FocusKeys {
|
|
4
4
|
ArrowHorizontal = 1,
|
|
5
5
|
ArrowVertical = 2,
|
|
@@ -10,6 +10,7 @@ export declare enum FocusKeys {
|
|
|
10
10
|
WS = 32,
|
|
11
11
|
AD = 64,
|
|
12
12
|
Tab = 128,
|
|
13
|
+
Backspace = 512,
|
|
13
14
|
ArrowAll = 3,
|
|
14
15
|
HJKL = 12,
|
|
15
16
|
WASD = 96,
|
|
@@ -24,7 +25,6 @@ export interface FocusZoneSettings {
|
|
|
24
25
|
activeDescendantControl?: HTMLElement;
|
|
25
26
|
onActiveDescendantChanged?: (newActiveDescendant: HTMLElement | undefined, previousActiveDescendant: HTMLElement | undefined, directlyActivated: boolean) => void;
|
|
26
27
|
focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
|
|
27
|
-
preventScroll?: boolean;
|
|
28
28
|
}
|
|
29
29
|
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
|
30
30
|
export declare const activeDescendantActivatedDirectly = "activated-directly";
|
package/dist/esm/focus-zone.js
CHANGED
|
@@ -14,6 +14,7 @@ export var FocusKeys;
|
|
|
14
14
|
FocusKeys[FocusKeys["WS"] = 32] = "WS";
|
|
15
15
|
FocusKeys[FocusKeys["AD"] = 64] = "AD";
|
|
16
16
|
FocusKeys[FocusKeys["Tab"] = 128] = "Tab";
|
|
17
|
+
FocusKeys[FocusKeys["Backspace"] = 512] = "Backspace";
|
|
17
18
|
FocusKeys[FocusKeys["ArrowAll"] = 3] = "ArrowAll";
|
|
18
19
|
FocusKeys[FocusKeys["HJKL"] = 12] = "HJKL";
|
|
19
20
|
FocusKeys[FocusKeys["WASD"] = 96] = "WASD";
|
|
@@ -36,7 +37,8 @@ const KEY_TO_BIT = {
|
|
|
36
37
|
Home: FocusKeys.HomeAndEnd,
|
|
37
38
|
End: FocusKeys.HomeAndEnd,
|
|
38
39
|
PageUp: FocusKeys.PageUpDown,
|
|
39
|
-
PageDown: FocusKeys.PageUpDown
|
|
40
|
+
PageDown: FocusKeys.PageUpDown,
|
|
41
|
+
Backspace: FocusKeys.Backspace
|
|
40
42
|
};
|
|
41
43
|
const KEY_TO_DIRECTION = {
|
|
42
44
|
ArrowLeft: 'previous',
|
|
@@ -55,7 +57,8 @@ const KEY_TO_DIRECTION = {
|
|
|
55
57
|
Home: 'start',
|
|
56
58
|
End: 'end',
|
|
57
59
|
PageUp: 'start',
|
|
58
|
-
PageDown: 'end'
|
|
60
|
+
PageDown: 'end',
|
|
61
|
+
Backspace: 'previous'
|
|
59
62
|
};
|
|
60
63
|
function getDirection(keyboardEvent) {
|
|
61
64
|
const direction = KEY_TO_DIRECTION[keyboardEvent.key];
|
|
@@ -121,7 +124,7 @@ export const activeDescendantActivatedDirectly = 'activated-directly';
|
|
|
121
124
|
export const activeDescendantActivatedIndirectly = 'activated-indirectly';
|
|
122
125
|
export const hasActiveDescendantAttribute = 'data-has-active-descendant';
|
|
123
126
|
export function focusZone(container, settings) {
|
|
124
|
-
var _a, _b, _c, _d
|
|
127
|
+
var _a, _b, _c, _d;
|
|
125
128
|
const focusableElements = [];
|
|
126
129
|
const savedTabIndex = new WeakMap();
|
|
127
130
|
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;
|
|
@@ -130,7 +133,6 @@ export function focusZone(container, settings) {
|
|
|
130
133
|
const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
|
|
131
134
|
const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
|
|
132
135
|
let currentFocusedElement;
|
|
133
|
-
const preventScroll = (_d = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _d !== void 0 ? _d : false;
|
|
134
136
|
function getFirstFocusableElement() {
|
|
135
137
|
return focusableElements[0];
|
|
136
138
|
}
|
|
@@ -241,7 +243,7 @@ export function focusZone(container, settings) {
|
|
|
241
243
|
childList: true
|
|
242
244
|
});
|
|
243
245
|
const controller = new AbortController();
|
|
244
|
-
const signal = (
|
|
246
|
+
const signal = (_d = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _d !== void 0 ? _d : controller.signal;
|
|
245
247
|
signal.addEventListener('abort', () => {
|
|
246
248
|
endFocusManagement(...focusableElements);
|
|
247
249
|
});
|
|
@@ -254,7 +256,7 @@ export function focusZone(container, settings) {
|
|
|
254
256
|
if (activeDescendantControl) {
|
|
255
257
|
container.addEventListener('focusin', event => {
|
|
256
258
|
if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
|
|
257
|
-
activeDescendantControl.focus(
|
|
259
|
+
activeDescendantControl.focus();
|
|
258
260
|
updateFocusedElement(event.target);
|
|
259
261
|
}
|
|
260
262
|
});
|
|
@@ -298,7 +300,7 @@ export function focusZone(container, settings) {
|
|
|
298
300
|
if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
|
|
299
301
|
const targetElementIndex = lastKeyboardFocusDirection === 'previous' ? focusableElements.length - 1 : 0;
|
|
300
302
|
const targetElement = focusableElements[targetElementIndex];
|
|
301
|
-
targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus(
|
|
303
|
+
targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus();
|
|
302
304
|
return;
|
|
303
305
|
}
|
|
304
306
|
else {
|
|
@@ -310,7 +312,7 @@ export function focusZone(container, settings) {
|
|
|
310
312
|
const elementToFocus = focusInStrategy(event.relatedTarget);
|
|
311
313
|
const requestedFocusElementIndex = elementToFocus ? focusableElements.indexOf(elementToFocus) : -1;
|
|
312
314
|
if (requestedFocusElementIndex >= 0 && elementToFocus instanceof HTMLElement) {
|
|
313
|
-
elementToFocus.focus(
|
|
315
|
+
elementToFocus.focus();
|
|
314
316
|
return;
|
|
315
317
|
}
|
|
316
318
|
else {
|
|
@@ -395,7 +397,7 @@ export function focusZone(container, settings) {
|
|
|
395
397
|
}
|
|
396
398
|
else if (nextElementToFocus) {
|
|
397
399
|
lastKeyboardFocusDirection = direction;
|
|
398
|
-
nextElementToFocus.focus(
|
|
400
|
+
nextElementToFocus.focus();
|
|
399
401
|
}
|
|
400
402
|
if (event.key !== 'Tab' || nextElementToFocus) {
|
|
401
403
|
event.preventDefault();
|