@primer/behaviors 0.0.0-202201892424 → 0.0.0-2022027213841
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 +1 -0
- package/dist/cjs/focus-trap.js +86 -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 +9 -0
- package/dist/cjs/utils/iterate-focusable-elements.js +68 -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 +1 -0
- package/dist/esm/focus-trap.js +82 -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 +9 -0
- package/dist/esm/utils/iterate-focusable-elements.js +61 -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/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/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
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
export declare type AnchorAlignment = 'start' | 'center' | 'end';
|
|
2
|
-
export declare type AnchorSide = 'inside-top' | 'inside-bottom' | 'inside-left' | 'inside-right' | 'inside-center' | 'outside-top' | 'outside-bottom' | 'outside-left' | 'outside-right';
|
|
3
|
-
/**
|
|
4
|
-
* Settings that customize how a floating element is positioned
|
|
5
|
-
* with respect to an anchor element.
|
|
6
|
-
*/
|
|
7
|
-
export interface PositionSettings {
|
|
8
|
-
/**
|
|
9
|
-
* Sets the side of the anchor element that the floating element should be
|
|
10
|
-
* pinned to. This side is given by a string starting with either "inside" or
|
|
11
|
-
* "outside", followed by a hyphen, followed by either "top", "right", "bottom",
|
|
12
|
-
* or "left". Additionally, "inside-center" is an allowed value.
|
|
13
|
-
*
|
|
14
|
-
* The first part of this string, "inside" or "outside", determines whether the
|
|
15
|
-
* floating element should be attempted to be placed "inside" the anchor element
|
|
16
|
-
* or "outside" of it. Using "inside" is useful for making it appear that the
|
|
17
|
-
* anchor _contains_ the floating element, and it can be used for implementing a
|
|
18
|
-
* dialog that is centered on the screen. The "outside" value is more common and
|
|
19
|
-
* can be used for tooltips, popovers, menus, etc.
|
|
20
|
-
*
|
|
21
|
-
* The second part of this string determines the _edge_ on the anchor element that
|
|
22
|
-
* the floating element will be anchored to. If side is "inside-center", then
|
|
23
|
-
* the floating element will be centered in the X-direction (while align is used
|
|
24
|
-
* to position it in the Y-direction).
|
|
25
|
-
* Note: "outside-center" is _not_ a valid value for this property.
|
|
26
|
-
*/
|
|
27
|
-
side: AnchorSide;
|
|
28
|
-
/**
|
|
29
|
-
* Determines how the floating element should align with the anchor element. If
|
|
30
|
-
* set to "start", the floating element's first edge (top or left) will align
|
|
31
|
-
* with the anchor element's first edge. If set to "center", the floating
|
|
32
|
-
* element will be centered along the axis of the anchor edge. If set to "end",
|
|
33
|
-
* the floating element's last edge will align with the anchor element's last edge.
|
|
34
|
-
*/
|
|
35
|
-
align: AnchorAlignment;
|
|
36
|
-
/**
|
|
37
|
-
* The number of pixels between the anchor edge and the floating element.
|
|
38
|
-
*
|
|
39
|
-
* Positive values move the floating element farther from the anchor element
|
|
40
|
-
* (for outside positioning) or further inside the anchor element (for inside
|
|
41
|
-
* positioning). Negative values have the opposite effect.
|
|
42
|
-
*/
|
|
43
|
-
anchorOffset: number;
|
|
44
|
-
/**
|
|
45
|
-
* An additional offset, in pixels, to move the floating element from
|
|
46
|
-
* the aligning edge.
|
|
47
|
-
*
|
|
48
|
-
* Positive values move the floating element in the direction of center-
|
|
49
|
-
* alignment. Negative values move the floating element away from center-
|
|
50
|
-
* alignment. When align is "center", positive offsets move the floating
|
|
51
|
-
* element right (top or bottom anchor side) or down (left or right
|
|
52
|
-
* anchor side).
|
|
53
|
-
*/
|
|
54
|
-
alignmentOffset: number;
|
|
55
|
-
/**
|
|
56
|
-
* If false, when the above settings result in rendering the floating element
|
|
57
|
-
* wholly or partially outside of the bounds of the containing element, attempt
|
|
58
|
-
* to adjust the settings to prevent this. Only applies to "outside" positioning.
|
|
59
|
-
*
|
|
60
|
-
* First, attempt to flip to the opposite edge of the anchor if the floating
|
|
61
|
-
* element is getting clipped in that direction. If flipping results in a
|
|
62
|
-
* similar clipping, try moving to the adjacent sides.
|
|
63
|
-
*
|
|
64
|
-
* Once we find a side that does not clip the overlay in its own dimension,
|
|
65
|
-
* check the rest of the sides to see if we need to adjust the alignment offset
|
|
66
|
-
* to fit in other dimensions.
|
|
67
|
-
*
|
|
68
|
-
* If we try all four sides and get clipped each time, settle for overflowing
|
|
69
|
-
* and use the "bottom" side, since the ability to scroll is most likely in
|
|
70
|
-
* this direction.
|
|
71
|
-
*/
|
|
72
|
-
allowOutOfBounds: boolean;
|
|
73
|
-
}
|
|
74
|
-
export interface AnchorPosition {
|
|
75
|
-
top: number;
|
|
76
|
-
left: number;
|
|
77
|
-
anchorSide: AnchorSide;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Given a floating element and an anchor element, return coordinates for the top-left
|
|
81
|
-
* of the floating element in order to absolutely position it such that it appears
|
|
82
|
-
* near the anchor element.
|
|
83
|
-
*
|
|
84
|
-
* @param floatingElement Element intended to be positioned near or within an anchor
|
|
85
|
-
* @param anchorElement The element to serve as the position anchor
|
|
86
|
-
* @param settings Settings to determine the rules for positioning the floating element
|
|
87
|
-
* @returns {top: number, left: number} coordinates for the floating element
|
|
88
|
-
*/
|
|
89
|
-
export declare function getAnchoredPosition(floatingElement: Element, anchorElement: Element | DOMRect, settings?: Partial<PositionSettings>): AnchorPosition;
|