@primer/behaviors 1.2.0 → 1.3.0-rc.9cf9e61
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/CHANGELOG.md +57 -0
- package/dist/cjs/focus-zone.d.ts +1 -0
- package/dist/cjs/focus-zone.js +7 -6
- package/dist/esm/focus-zone.d.ts +1 -0
- package/dist/esm/focus-zone.js +7 -6
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @primer/behaviors
|
|
2
|
+
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#152](https://github.com/primer/behaviors/pull/152) [`afaf380`](https://github.com/primer/behaviors/commit/afaf380893cb858e6c85515bb490866d76d3d8b7) Thanks [@colebemis](https://github.com/colebemis)! - focusZone: Add `preventScroll` option
|
|
8
|
+
|
|
9
|
+
## 1.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#134](https://github.com/primer/behaviors/pull/134) [`cc5bf8e`](https://github.com/primer/behaviors/commit/cc5bf8e8404594bc6b3ff1493f253b171bfb03c0) Thanks [@jonrohan](https://github.com/jonrohan)! - Add Dimensions behavior
|
|
14
|
+
|
|
15
|
+
## 1.1.3
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#93](https://github.com/primer/behaviors/pull/93) [`e5aaf68`](https://github.com/primer/behaviors/commit/e5aaf688b084bf6e425c6bdb0963aa50aacf8fa4) Thanks [@siddharthkp](https://github.com/siddharthkp)! - Anchored position: Add check for boundary collision on left side
|
|
20
|
+
|
|
21
|
+
## 1.1.2
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [#78](https://github.com/primer/behaviors/pull/78) [`62e5459`](https://github.com/primer/behaviors/commit/62e545913dae8ca42f88fd6184f190cdf3df9c4c) Thanks [@siddharthkp](https://github.com/siddharthkp)! - Anchored Position: Add alternative alignments to flip to if there isn't enough space
|
|
26
|
+
|
|
27
|
+
## 1.1.1
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- [#73](https://github.com/primer/behaviors/pull/73) [`a96d60f`](https://github.com/primer/behaviors/commit/a96d60fdb2a2ffdde71a22ea29fa2c788bf4c6aa) Thanks [@dgreif](https://github.com/dgreif)! - Add `import` conditional export type to the package for better NodeJS ESM compatibility
|
|
32
|
+
|
|
33
|
+
## 1.1.0
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- [#52](https://github.com/primer/behaviors/pull/52) [`1aa3027`](https://github.com/primer/behaviors/commit/1aa302782e3c833f9d9c27f602a046e81f05c3e5) Thanks [@owenniblock](https://github.com/owenniblock)! - Update focusTrap to use new methodology after accessibility discussions
|
|
38
|
+
|
|
39
|
+
## 1.0.3
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- [#42](https://github.com/primer/behaviors/pull/42) [`41945a3`](https://github.com/primer/behaviors/commit/41945a37ef07da82ce5a29feb03d7a7d96ec76ea) Thanks [@dgreif](https://github.com/dgreif)! - Build both esm and cjs output for the package
|
|
44
|
+
|
|
45
|
+
## 1.0.2
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- [#17](https://github.com/primer/behaviors/pull/17) [`9194ba4`](https://github.com/primer/behaviors/commit/9194ba403502b4acba0be03bed1a765c1ba81340) Thanks [@dgreif](https://github.com/dgreif)! - Correct margin orientation for `scrollIntoView`
|
|
50
|
+
|
|
51
|
+
* [#18](https://github.com/primer/behaviors/pull/18) [`3b4dd41`](https://github.com/primer/behaviors/commit/3b4dd414175417f83bd144939fe74b2a01bc7136) Thanks [@dgreif](https://github.com/dgreif)! - Export utils as submodule
|
|
52
|
+
|
|
53
|
+
## 1.0.1
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- [#10](https://github.com/primer/behaviors/pull/10) [`88b6f34`](https://github.com/primer/behaviors/commit/88b6f34bf4874f3c81473020a01a58b197dd6e16) Thanks [@dgreif](https://github.com/dgreif)! - Set up changesets
|
package/dist/cjs/focus-zone.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface FocusZoneSettings {
|
|
|
24
24
|
activeDescendantControl?: HTMLElement;
|
|
25
25
|
onActiveDescendantChanged?: (newActiveDescendant: HTMLElement | undefined, previousActiveDescendant: HTMLElement | undefined, directlyActivated: boolean) => void;
|
|
26
26
|
focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
|
|
27
|
+
preventScroll?: boolean;
|
|
27
28
|
}
|
|
28
29
|
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
|
29
30
|
export declare const activeDescendantActivatedDirectly = "activated-directly";
|
package/dist/cjs/focus-zone.js
CHANGED
|
@@ -124,7 +124,7 @@ exports.activeDescendantActivatedDirectly = 'activated-directly';
|
|
|
124
124
|
exports.activeDescendantActivatedIndirectly = 'activated-indirectly';
|
|
125
125
|
exports.hasActiveDescendantAttribute = 'data-has-active-descendant';
|
|
126
126
|
function focusZone(container, settings) {
|
|
127
|
-
var _a, _b, _c, _d;
|
|
127
|
+
var _a, _b, _c, _d, _e;
|
|
128
128
|
const focusableElements = [];
|
|
129
129
|
const savedTabIndex = new WeakMap();
|
|
130
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;
|
|
@@ -133,6 +133,7 @@ function focusZone(container, settings) {
|
|
|
133
133
|
const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
|
|
134
134
|
const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
|
|
135
135
|
let currentFocusedElement;
|
|
136
|
+
const preventScroll = (_d = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _d !== void 0 ? _d : false;
|
|
136
137
|
function getFirstFocusableElement() {
|
|
137
138
|
return focusableElements[0];
|
|
138
139
|
}
|
|
@@ -243,7 +244,7 @@ function focusZone(container, settings) {
|
|
|
243
244
|
childList: true
|
|
244
245
|
});
|
|
245
246
|
const controller = new AbortController();
|
|
246
|
-
const signal = (
|
|
247
|
+
const signal = (_e = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _e !== void 0 ? _e : controller.signal;
|
|
247
248
|
signal.addEventListener('abort', () => {
|
|
248
249
|
endFocusManagement(...focusableElements);
|
|
249
250
|
});
|
|
@@ -256,7 +257,7 @@ function focusZone(container, settings) {
|
|
|
256
257
|
if (activeDescendantControl) {
|
|
257
258
|
container.addEventListener('focusin', event => {
|
|
258
259
|
if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
|
|
259
|
-
activeDescendantControl.focus();
|
|
260
|
+
activeDescendantControl.focus({ preventScroll });
|
|
260
261
|
updateFocusedElement(event.target);
|
|
261
262
|
}
|
|
262
263
|
});
|
|
@@ -300,7 +301,7 @@ function focusZone(container, settings) {
|
|
|
300
301
|
if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
|
|
301
302
|
const targetElementIndex = lastKeyboardFocusDirection === 'previous' ? focusableElements.length - 1 : 0;
|
|
302
303
|
const targetElement = focusableElements[targetElementIndex];
|
|
303
|
-
targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus();
|
|
304
|
+
targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus({ preventScroll });
|
|
304
305
|
return;
|
|
305
306
|
}
|
|
306
307
|
else {
|
|
@@ -312,7 +313,7 @@ function focusZone(container, settings) {
|
|
|
312
313
|
const elementToFocus = focusInStrategy(event.relatedTarget);
|
|
313
314
|
const requestedFocusElementIndex = elementToFocus ? focusableElements.indexOf(elementToFocus) : -1;
|
|
314
315
|
if (requestedFocusElementIndex >= 0 && elementToFocus instanceof HTMLElement) {
|
|
315
|
-
elementToFocus.focus();
|
|
316
|
+
elementToFocus.focus({ preventScroll });
|
|
316
317
|
return;
|
|
317
318
|
}
|
|
318
319
|
else {
|
|
@@ -397,7 +398,7 @@ function focusZone(container, settings) {
|
|
|
397
398
|
}
|
|
398
399
|
else if (nextElementToFocus) {
|
|
399
400
|
lastKeyboardFocusDirection = direction;
|
|
400
|
-
nextElementToFocus.focus();
|
|
401
|
+
nextElementToFocus.focus({ preventScroll });
|
|
401
402
|
}
|
|
402
403
|
if (event.key !== 'Tab' || nextElementToFocus) {
|
|
403
404
|
event.preventDefault();
|
package/dist/esm/focus-zone.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface FocusZoneSettings {
|
|
|
24
24
|
activeDescendantControl?: HTMLElement;
|
|
25
25
|
onActiveDescendantChanged?: (newActiveDescendant: HTMLElement | undefined, previousActiveDescendant: HTMLElement | undefined, directlyActivated: boolean) => void;
|
|
26
26
|
focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
|
|
27
|
+
preventScroll?: boolean;
|
|
27
28
|
}
|
|
28
29
|
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
|
29
30
|
export declare const activeDescendantActivatedDirectly = "activated-directly";
|
package/dist/esm/focus-zone.js
CHANGED
|
@@ -121,7 +121,7 @@ export const activeDescendantActivatedDirectly = 'activated-directly';
|
|
|
121
121
|
export const activeDescendantActivatedIndirectly = 'activated-indirectly';
|
|
122
122
|
export const hasActiveDescendantAttribute = 'data-has-active-descendant';
|
|
123
123
|
export function focusZone(container, settings) {
|
|
124
|
-
var _a, _b, _c, _d;
|
|
124
|
+
var _a, _b, _c, _d, _e;
|
|
125
125
|
const focusableElements = [];
|
|
126
126
|
const savedTabIndex = new WeakMap();
|
|
127
127
|
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,6 +130,7 @@ export function focusZone(container, settings) {
|
|
|
130
130
|
const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
|
|
131
131
|
const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
|
|
132
132
|
let currentFocusedElement;
|
|
133
|
+
const preventScroll = (_d = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _d !== void 0 ? _d : false;
|
|
133
134
|
function getFirstFocusableElement() {
|
|
134
135
|
return focusableElements[0];
|
|
135
136
|
}
|
|
@@ -240,7 +241,7 @@ export function focusZone(container, settings) {
|
|
|
240
241
|
childList: true
|
|
241
242
|
});
|
|
242
243
|
const controller = new AbortController();
|
|
243
|
-
const signal = (
|
|
244
|
+
const signal = (_e = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _e !== void 0 ? _e : controller.signal;
|
|
244
245
|
signal.addEventListener('abort', () => {
|
|
245
246
|
endFocusManagement(...focusableElements);
|
|
246
247
|
});
|
|
@@ -253,7 +254,7 @@ export function focusZone(container, settings) {
|
|
|
253
254
|
if (activeDescendantControl) {
|
|
254
255
|
container.addEventListener('focusin', event => {
|
|
255
256
|
if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
|
|
256
|
-
activeDescendantControl.focus();
|
|
257
|
+
activeDescendantControl.focus({ preventScroll });
|
|
257
258
|
updateFocusedElement(event.target);
|
|
258
259
|
}
|
|
259
260
|
});
|
|
@@ -297,7 +298,7 @@ export function focusZone(container, settings) {
|
|
|
297
298
|
if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
|
|
298
299
|
const targetElementIndex = lastKeyboardFocusDirection === 'previous' ? focusableElements.length - 1 : 0;
|
|
299
300
|
const targetElement = focusableElements[targetElementIndex];
|
|
300
|
-
targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus();
|
|
301
|
+
targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus({ preventScroll });
|
|
301
302
|
return;
|
|
302
303
|
}
|
|
303
304
|
else {
|
|
@@ -309,7 +310,7 @@ export function focusZone(container, settings) {
|
|
|
309
310
|
const elementToFocus = focusInStrategy(event.relatedTarget);
|
|
310
311
|
const requestedFocusElementIndex = elementToFocus ? focusableElements.indexOf(elementToFocus) : -1;
|
|
311
312
|
if (requestedFocusElementIndex >= 0 && elementToFocus instanceof HTMLElement) {
|
|
312
|
-
elementToFocus.focus();
|
|
313
|
+
elementToFocus.focus({ preventScroll });
|
|
313
314
|
return;
|
|
314
315
|
}
|
|
315
316
|
else {
|
|
@@ -394,7 +395,7 @@ export function focusZone(container, settings) {
|
|
|
394
395
|
}
|
|
395
396
|
else if (nextElementToFocus) {
|
|
396
397
|
lastKeyboardFocusDirection = direction;
|
|
397
|
-
nextElementToFocus.focus();
|
|
398
|
+
nextElementToFocus.focus({ preventScroll });
|
|
398
399
|
}
|
|
399
400
|
if (event.key !== 'Tab' || nextElementToFocus) {
|
|
400
401
|
event.preventDefault();
|