@primer/behaviors 0.0.0-202201891142 → 0.0.0-2022020145740
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/anchored-position.d.ts +15 -0
- package/dist/cjs/anchored-position.js +210 -0
- package/dist/cjs/focus-trap.d.ts +2 -0
- package/dist/cjs/focus-trap.js +111 -0
- package/dist/cjs/focus-zone.d.ts +32 -0
- package/dist/cjs/focus-zone.js +410 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- package/dist/cjs/index.js +16 -0
- package/dist/{polyfills → cjs/polyfills}/event-listener-signal.d.ts +0 -0
- package/dist/cjs/polyfills/event-listener-signal.js +44 -0
- package/dist/{scroll-into-view.d.ts → cjs/scroll-into-view.d.ts} +0 -0
- package/dist/cjs/scroll-into-view.js +21 -0
- package/dist/{utils → cjs/utils}/index.d.ts +0 -0
- package/dist/cjs/utils/index.js +15 -0
- package/dist/cjs/utils/iterate-focusable-elements.d.ts +8 -0
- package/dist/cjs/utils/iterate-focusable-elements.js +63 -0
- package/dist/{utils → cjs/utils}/unique-id.d.ts +0 -0
- package/dist/cjs/utils/unique-id.js +8 -0
- package/dist/{utils → cjs/utils}/user-agent.d.ts +0 -0
- package/dist/cjs/utils/user-agent.js +11 -0
- package/dist/esm/anchored-position.d.ts +15 -0
- package/dist/esm/anchored-position.js +206 -0
- package/dist/esm/focus-trap.d.ts +2 -0
- package/dist/esm/focus-trap.js +107 -0
- package/dist/esm/focus-zone.d.ts +32 -0
- package/dist/esm/focus-zone.js +406 -0
- package/{lib-esm → dist/esm}/index.d.ts +0 -0
- package/{lib/index.d.ts → dist/esm/index.js} +0 -0
- package/{lib-esm → dist/esm}/polyfills/event-listener-signal.d.ts +0 -0
- package/dist/esm/polyfills/event-listener-signal.js +40 -0
- package/{lib-esm → dist/esm}/scroll-into-view.d.ts +0 -0
- package/dist/esm/scroll-into-view.js +17 -0
- package/{lib-esm → dist/esm}/utils/index.d.ts +0 -0
- package/{lib/utils/index.d.ts → dist/esm/utils/index.js} +0 -0
- package/dist/esm/utils/iterate-focusable-elements.d.ts +8 -0
- package/dist/esm/utils/iterate-focusable-elements.js +57 -0
- package/{lib-esm → dist/esm}/utils/unique-id.d.ts +0 -0
- package/dist/esm/utils/unique-id.js +4 -0
- package/{lib-esm → dist/esm}/utils/user-agent.d.ts +0 -0
- package/dist/esm/utils/user-agent.js +7 -0
- package/package.json +18 -30
- package/utils/package.json +6 -6
- package/dist/anchored-position.d.ts +0 -89
- package/dist/focus-trap.d.ts +0 -12
- package/dist/focus-zone.d.ts +0 -137
- package/dist/utils/iterate-focusable-elements.d.ts +0 -42
- package/lib/__tests__/anchored-position.test.js +0 -388
- package/lib/__tests__/scroll-into-view.test.js +0 -245
- package/lib/anchored-position.d.ts +0 -89
- package/lib/anchored-position.js +0 -316
- package/lib/focus-trap.d.ts +0 -12
- package/lib/focus-trap.js +0 -179
- package/lib/focus-zone.d.ts +0 -137
- package/lib/focus-zone.js +0 -578
- package/lib/index.js +0 -57
- package/lib/polyfills/event-listener-signal.d.ts +0 -6
- package/lib/polyfills/event-listener-signal.js +0 -64
- package/lib/scroll-into-view.d.ts +0 -7
- package/lib/scroll-into-view.js +0 -42
- package/lib/utils/index.js +0 -44
- package/lib/utils/iterate-focusable-elements.d.ts +0 -42
- package/lib/utils/iterate-focusable-elements.js +0 -113
- package/lib/utils/unique-id.d.ts +0 -1
- package/lib/utils/unique-id.js +0 -12
- package/lib/utils/user-agent.d.ts +0 -1
- package/lib/utils/user-agent.js +0 -15
- package/lib-esm/__tests__/anchored-position.test.js +0 -386
- package/lib-esm/__tests__/scroll-into-view.test.js +0 -243
- package/lib-esm/anchored-position.d.ts +0 -89
- package/lib-esm/anchored-position.js +0 -309
- package/lib-esm/focus-trap.d.ts +0 -12
- package/lib-esm/focus-trap.js +0 -170
- package/lib-esm/focus-zone.d.ts +0 -137
- package/lib-esm/focus-zone.js +0 -559
- package/lib-esm/index.js +0 -4
- package/lib-esm/polyfills/event-listener-signal.js +0 -57
- package/lib-esm/scroll-into-view.js +0 -35
- package/lib-esm/utils/index.js +0 -3
- package/lib-esm/utils/iterate-focusable-elements.d.ts +0 -42
- package/lib-esm/utils/iterate-focusable-elements.js +0 -102
- package/lib-esm/utils/unique-id.js +0 -5
- package/lib-esm/utils/user-agent.js +0 -8
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.polyfill = polyfill;
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
|
|
10
|
-
This file polyfills the following: https://github.com/whatwg/dom/issues/911
|
|
11
|
-
Once all targeted browsers support this DOM feature, this polyfill can be deleted.
|
|
12
|
-
|
|
13
|
-
This allows users to pass an AbortSignal to a call to addEventListener as part of the
|
|
14
|
-
AddEventListenerOptions object. When the signal is aborted, the event listener is
|
|
15
|
-
removed.
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
let signalSupported = false; // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
19
|
-
|
|
20
|
-
function noop() {}
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const options = Object.create({}, {
|
|
24
|
-
signal: {
|
|
25
|
-
get() {
|
|
26
|
-
signalSupported = true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
window.addEventListener('test', noop, options);
|
|
32
|
-
window.removeEventListener('test', noop, options);
|
|
33
|
-
} catch (e) {
|
|
34
|
-
/* */
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function featureSupported() {
|
|
38
|
-
return signalSupported;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function monkeyPatch() {
|
|
42
|
-
if (typeof window === 'undefined') {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const originalAddEventListener = EventTarget.prototype.addEventListener;
|
|
47
|
-
|
|
48
|
-
EventTarget.prototype.addEventListener = function (name, originalCallback, optionsOrCapture) {
|
|
49
|
-
if (typeof optionsOrCapture === 'object' && 'signal' in optionsOrCapture && optionsOrCapture.signal instanceof AbortSignal) {
|
|
50
|
-
originalAddEventListener.call(optionsOrCapture.signal, 'abort', () => {
|
|
51
|
-
this.removeEventListener(name, originalCallback, optionsOrCapture);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return originalAddEventListener.call(this, name, originalCallback, optionsOrCapture);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function polyfill() {
|
|
60
|
-
if (!featureSupported()) {
|
|
61
|
-
monkeyPatch();
|
|
62
|
-
signalSupported = true;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export interface ScrollIntoViewOptions {
|
|
2
|
-
direction?: 'horizontal' | 'vertical';
|
|
3
|
-
startMargin?: number;
|
|
4
|
-
endMargin?: number;
|
|
5
|
-
behavior?: ScrollBehavior;
|
|
6
|
-
}
|
|
7
|
-
export declare function scrollIntoView(child: HTMLElement, viewingArea: HTMLElement, { direction, startMargin, endMargin, behavior }?: ScrollIntoViewOptions): void;
|
package/lib/scroll-into-view.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.scrollIntoView = scrollIntoView;
|
|
7
|
-
|
|
8
|
-
function scrollIntoView(child, viewingArea, {
|
|
9
|
-
direction = 'vertical',
|
|
10
|
-
startMargin = 0,
|
|
11
|
-
endMargin = 0,
|
|
12
|
-
behavior = 'smooth'
|
|
13
|
-
} = {}) {
|
|
14
|
-
const startSide = direction === 'vertical' ? 'top' : 'left';
|
|
15
|
-
const endSide = direction === 'vertical' ? 'bottom' : 'right';
|
|
16
|
-
const scrollSide = direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
|
|
17
|
-
const {
|
|
18
|
-
[startSide]: childStart,
|
|
19
|
-
[endSide]: childEnd
|
|
20
|
-
} = child.getBoundingClientRect();
|
|
21
|
-
const {
|
|
22
|
-
[startSide]: viewingAreaStart,
|
|
23
|
-
[endSide]: viewingAreaEnd
|
|
24
|
-
} = viewingArea.getBoundingClientRect();
|
|
25
|
-
const isChildStartAboveViewingArea = childStart < viewingAreaStart + startMargin;
|
|
26
|
-
const isChildBottomBelowViewingArea = childEnd > viewingAreaEnd - endMargin;
|
|
27
|
-
|
|
28
|
-
if (isChildStartAboveViewingArea) {
|
|
29
|
-
const scrollHeightToChildStart = childStart - viewingAreaStart + viewingArea[scrollSide];
|
|
30
|
-
viewingArea.scrollTo({
|
|
31
|
-
behavior,
|
|
32
|
-
[startSide]: scrollHeightToChildStart - startMargin
|
|
33
|
-
});
|
|
34
|
-
} else if (isChildBottomBelowViewingArea) {
|
|
35
|
-
const scrollHeightToChildBottom = childEnd - viewingAreaEnd + viewingArea[scrollSide];
|
|
36
|
-
viewingArea.scrollTo({
|
|
37
|
-
behavior,
|
|
38
|
-
[startSide]: scrollHeightToChildBottom + endMargin
|
|
39
|
-
});
|
|
40
|
-
} // either completely in view or outside viewing area on both ends, don't scroll
|
|
41
|
-
|
|
42
|
-
}
|
package/lib/utils/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _iterateFocusableElements = require("./iterate-focusable-elements.js");
|
|
8
|
-
|
|
9
|
-
Object.keys(_iterateFocusableElements).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (key in exports && exports[key] === _iterateFocusableElements[key]) return;
|
|
12
|
-
Object.defineProperty(exports, key, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _iterateFocusableElements[key];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
var _uniqueId = require("./unique-id.js");
|
|
21
|
-
|
|
22
|
-
Object.keys(_uniqueId).forEach(function (key) {
|
|
23
|
-
if (key === "default" || key === "__esModule") return;
|
|
24
|
-
if (key in exports && exports[key] === _uniqueId[key]) return;
|
|
25
|
-
Object.defineProperty(exports, key, {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return _uniqueId[key];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
var _userAgent = require("./user-agent.js");
|
|
34
|
-
|
|
35
|
-
Object.keys(_userAgent).forEach(function (key) {
|
|
36
|
-
if (key === "default" || key === "__esModule") return;
|
|
37
|
-
if (key in exports && exports[key] === _userAgent[key]) return;
|
|
38
|
-
Object.defineProperty(exports, key, {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function () {
|
|
41
|
-
return _userAgent[key];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Options to the focusable elements iterator
|
|
3
|
-
*/
|
|
4
|
-
export interface IterateFocusableElements {
|
|
5
|
-
/**
|
|
6
|
-
* (Default: false) Iterate through focusable elements in reverse-order
|
|
7
|
-
*/
|
|
8
|
-
reverse?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* (Default: false) Perform additional checks to determine tabbability
|
|
11
|
-
* which may adversely affect app performance.
|
|
12
|
-
*/
|
|
13
|
-
strict?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* (Default: false) Only iterate tabbable elements, which is the subset
|
|
16
|
-
* of focusable elements that are part of the page's tab sequence.
|
|
17
|
-
*/
|
|
18
|
-
onlyTabbable?: boolean;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Returns an iterator over all of the focusable elements within `container`.
|
|
22
|
-
* Note: If `container` is itself focusable it will be included in the results.
|
|
23
|
-
* @param container The container over which to find focusable elements.
|
|
24
|
-
* @param reverse If true, iterate backwards through focusable elements.
|
|
25
|
-
*/
|
|
26
|
-
export declare function iterateFocusableElements(container: HTMLElement, options?: IterateFocusableElements): Generator<HTMLElement, undefined, undefined>;
|
|
27
|
-
/**
|
|
28
|
-
* Determines whether the given element is focusable. If `strict` is true, we may
|
|
29
|
-
* perform additional checks that require a reflow (less performant).
|
|
30
|
-
* @param elem
|
|
31
|
-
* @param strict
|
|
32
|
-
*/
|
|
33
|
-
export declare function isFocusable(elem: HTMLElement, strict?: boolean): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Determines whether the given element is tabbable. If `strict` is true, we may
|
|
36
|
-
* perform additional checks that require a reflow (less performant). This check
|
|
37
|
-
* ensures that the element is focusable and that its tabindex is not explicitly
|
|
38
|
-
* set to "-1" (which makes it focusable, but removes it from the tab order).
|
|
39
|
-
* @param elem
|
|
40
|
-
* @param strict
|
|
41
|
-
*/
|
|
42
|
-
export declare function isTabbable(elem: HTMLElement, strict?: boolean): boolean;
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isFocusable = isFocusable;
|
|
7
|
-
exports.isTabbable = isTabbable;
|
|
8
|
-
exports.iterateFocusableElements = iterateFocusableElements;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Options to the focusable elements iterator
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Returns an iterator over all of the focusable elements within `container`.
|
|
16
|
-
* Note: If `container` is itself focusable it will be included in the results.
|
|
17
|
-
* @param container The container over which to find focusable elements.
|
|
18
|
-
* @param reverse If true, iterate backwards through focusable elements.
|
|
19
|
-
*/
|
|
20
|
-
function* iterateFocusableElements(container, options = {}) {
|
|
21
|
-
var _options$strict, _options$onlyTabbable;
|
|
22
|
-
|
|
23
|
-
const strict = (_options$strict = options.strict) !== null && _options$strict !== void 0 ? _options$strict : false;
|
|
24
|
-
const acceptFn = ((_options$onlyTabbable = options.onlyTabbable) !== null && _options$onlyTabbable !== void 0 ? _options$onlyTabbable : false) ? isTabbable : isFocusable;
|
|
25
|
-
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
26
|
-
acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
27
|
-
});
|
|
28
|
-
let nextNode = null; // Allow the container to participate
|
|
29
|
-
|
|
30
|
-
if (!options.reverse && acceptFn(container, strict)) {
|
|
31
|
-
yield container;
|
|
32
|
-
} // If iterating in reverse, continue traversing down into the last child until we reach
|
|
33
|
-
// a leaf DOM node
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (options.reverse) {
|
|
37
|
-
let lastChild = walker.lastChild();
|
|
38
|
-
|
|
39
|
-
while (lastChild) {
|
|
40
|
-
nextNode = lastChild;
|
|
41
|
-
lastChild = walker.lastChild();
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
nextNode = walker.firstChild();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
while (nextNode instanceof HTMLElement) {
|
|
48
|
-
yield nextNode;
|
|
49
|
-
nextNode = options.reverse ? walker.previousNode() : walker.nextNode();
|
|
50
|
-
} // Allow the container to participate (in reverse)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (options.reverse && acceptFn(container, strict)) {
|
|
54
|
-
yield container;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Determines whether the given element is focusable. If `strict` is true, we may
|
|
61
|
-
* perform additional checks that require a reflow (less performant).
|
|
62
|
-
* @param elem
|
|
63
|
-
* @param strict
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
function isFocusable(elem, strict = false) {
|
|
68
|
-
// Certain conditions cause an element to never be focusable, even if they have tabindex="0"
|
|
69
|
-
const disabledAttrInert = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTGROUP', 'OPTION', 'FIELDSET'].includes(elem.tagName) && elem.disabled;
|
|
70
|
-
const hiddenInert = elem.hidden;
|
|
71
|
-
const hiddenInputInert = elem instanceof HTMLInputElement && elem.type === 'hidden';
|
|
72
|
-
|
|
73
|
-
if (disabledAttrInert || hiddenInert || hiddenInputInert) {
|
|
74
|
-
return false;
|
|
75
|
-
} // Each of the conditions checked below require a reflow, thus are gated by the `strict`
|
|
76
|
-
// argument. If any are true, the element is not focusable, even if tabindex is set.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (strict) {
|
|
80
|
-
const sizeInert = elem.offsetWidth === 0 || elem.offsetHeight === 0;
|
|
81
|
-
const visibilityInert = ['hidden', 'collapse'].includes(getComputedStyle(elem).visibility);
|
|
82
|
-
const clientRectsInert = elem.getClientRects().length === 0;
|
|
83
|
-
|
|
84
|
-
if (sizeInert || visibilityInert || clientRectsInert) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
} // Any element with `tabindex` explicitly set can be focusable, even if it's set to "-1"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (elem.getAttribute('tabindex') != null) {
|
|
91
|
-
return true;
|
|
92
|
-
} // One last way `elem.tabIndex` can be wrong.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (elem instanceof HTMLAnchorElement && elem.getAttribute('href') == null) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return elem.tabIndex !== -1;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Determines whether the given element is tabbable. If `strict` is true, we may
|
|
103
|
-
* perform additional checks that require a reflow (less performant). This check
|
|
104
|
-
* ensures that the element is focusable and that its tabindex is not explicitly
|
|
105
|
-
* set to "-1" (which makes it focusable, but removes it from the tab order).
|
|
106
|
-
* @param elem
|
|
107
|
-
* @param strict
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
function isTabbable(elem, strict = false) {
|
|
112
|
-
return isFocusable(elem, strict) && elem.getAttribute('tabindex') !== '-1';
|
|
113
|
-
}
|
package/lib/utils/unique-id.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function uniqueId(): string;
|
package/lib/utils/unique-id.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.uniqueId = uniqueId;
|
|
7
|
-
// Note: uniqueId may be unsafe in SSR contexts if it is used create DOM IDs or otherwise cause a hydration warning. Use useSSRSafeId instead.
|
|
8
|
-
let idSeed = 10000;
|
|
9
|
-
|
|
10
|
-
function uniqueId() {
|
|
11
|
-
return `__primer_id_${idSeed++}`;
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isMacOS(): boolean;
|
package/lib/utils/user-agent.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isMacOS = isMacOS;
|
|
7
|
-
let isMac = undefined;
|
|
8
|
-
|
|
9
|
-
function isMacOS() {
|
|
10
|
-
if (isMac === undefined) {
|
|
11
|
-
isMac = /^mac/i.test(window.navigator.platform);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return isMac;
|
|
15
|
-
}
|