@react-aria/overlays 3.8.0 → 3.9.0
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/main.js +34 -23
- package/dist/main.js.map +1 -1
- package/dist/module.js +34 -23
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -13
- package/src/calculatePosition.ts +11 -9
- package/src/useOverlay.ts +1 -0
- package/src/useOverlayPosition.ts +1 -1
- package/src/usePreventScroll.ts +24 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/overlays",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,22 +18,23 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/i18n": "^3.
|
|
22
|
-
"@react-aria/interactions": "^3.
|
|
23
|
-
"@react-aria/utils": "^3.
|
|
24
|
-
"@react-aria/visually-hidden": "^3.
|
|
25
|
-
"@react-stately/overlays": "^3.
|
|
26
|
-
"@react-types/button": "^3.
|
|
27
|
-
"@react-types/overlays": "^3.
|
|
28
|
-
"@react-types/shared": "^3.
|
|
29
|
-
"dom-helpers": "^
|
|
21
|
+
"@react-aria/i18n": "^3.4.0",
|
|
22
|
+
"@react-aria/interactions": "^3.9.0",
|
|
23
|
+
"@react-aria/utils": "^3.13.0",
|
|
24
|
+
"@react-aria/visually-hidden": "^3.3.0",
|
|
25
|
+
"@react-stately/overlays": "^3.3.0",
|
|
26
|
+
"@react-types/button": "^3.5.0",
|
|
27
|
+
"@react-types/overlays": "^3.6.0",
|
|
28
|
+
"@react-types/shared": "^3.13.0",
|
|
29
|
+
"dom-helpers": "^5.2.1",
|
|
30
|
+
"react-transition-group": "^4.4.2"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
|
-
"react": "^16.8.0 || ^17.0.0-rc.1",
|
|
33
|
-
"react-dom": "^16.8.0 || ^17.0.0-rc.1"
|
|
33
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0",
|
|
34
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
34
35
|
},
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "8f921ec5094e7c2b3c301bcb6133372e35a2052b"
|
|
39
40
|
}
|
package/src/calculatePosition.ts
CHANGED
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {Axis, Placement, PlacementAxis, SizeAxis} from '@react-types/overlays';
|
|
14
|
-
import getCss from 'dom-helpers/
|
|
15
|
-
import getOffset from 'dom-helpers/
|
|
16
|
-
import getPosition from 'dom-helpers/
|
|
17
|
-
import getScrollLeft from 'dom-helpers/
|
|
18
|
-
import getScrollTop from 'dom-helpers/
|
|
14
|
+
import getCss from 'dom-helpers/css';
|
|
15
|
+
import getOffset from 'dom-helpers/offset';
|
|
16
|
+
import getPosition from 'dom-helpers/position';
|
|
17
|
+
import getScrollLeft from 'dom-helpers/scrollLeft';
|
|
18
|
+
import getScrollTop from 'dom-helpers/scrollTop';
|
|
19
19
|
import ownerDocument from 'dom-helpers/ownerDocument';
|
|
20
20
|
|
|
21
21
|
interface Position {
|
|
@@ -99,7 +99,7 @@ const PARSED_PLACEMENT_CACHE = {};
|
|
|
99
99
|
// @ts-ignore
|
|
100
100
|
let visualViewport = typeof window !== 'undefined' && window.visualViewport;
|
|
101
101
|
|
|
102
|
-
function getContainerDimensions(containerNode:
|
|
102
|
+
function getContainerDimensions(containerNode: HTMLElement): Dimensions {
|
|
103
103
|
let width = 0, height = 0, top = 0, left = 0;
|
|
104
104
|
let scroll: Position = {};
|
|
105
105
|
|
|
@@ -373,15 +373,17 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
|
|
|
373
373
|
maxHeight
|
|
374
374
|
} = opts;
|
|
375
375
|
|
|
376
|
-
let container = overlayNode.offsetParent || document.body;
|
|
376
|
+
let container = (overlayNode.offsetParent || document.body) as HTMLElement;
|
|
377
377
|
let isBodyContainer = container.tagName === 'BODY';
|
|
378
378
|
const containerPositionStyle = window.getComputedStyle(container).position;
|
|
379
379
|
let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';
|
|
380
380
|
let childOffset: Offset = isBodyContainer ? getOffset(targetNode) : getPosition(targetNode, container);
|
|
381
381
|
|
|
382
382
|
if (!isBodyContainer) {
|
|
383
|
-
|
|
384
|
-
|
|
383
|
+
let marginTop = String(getCss(targetNode, 'marginTop'));
|
|
384
|
+
let marginLeft = String(getCss(targetNode, 'marginLeft'));
|
|
385
|
+
childOffset.top += parseInt(marginTop, 10) || 0;
|
|
386
|
+
childOffset.left += parseInt(marginLeft, 10) || 0;
|
|
385
387
|
}
|
|
386
388
|
|
|
387
389
|
let overlaySize: Offset = getOffset(overlayNode);
|
package/src/useOverlay.ts
CHANGED
|
@@ -111,6 +111,7 @@ export function useOverlay(props: OverlayProps, ref: RefObject<HTMLElement>): Ov
|
|
|
111
111
|
// Handle the escape key
|
|
112
112
|
let onKeyDown = (e) => {
|
|
113
113
|
if (e.key === 'Escape' && !isKeyboardDismissDisabled) {
|
|
114
|
+
e.stopPropagation();
|
|
114
115
|
e.preventDefault();
|
|
115
116
|
onHide();
|
|
116
117
|
}
|
|
@@ -44,7 +44,7 @@ interface AriaPositionProps extends PositionProps {
|
|
|
44
44
|
/** Handler that is called when the overlay should close. */
|
|
45
45
|
onClose?: () => void,
|
|
46
46
|
/**
|
|
47
|
-
* The maxHeight specified for the overlay element.
|
|
47
|
+
* The maxHeight specified for the overlay element.
|
|
48
48
|
* By default, it will take all space up to the current viewport height.
|
|
49
49
|
*/
|
|
50
50
|
maxHeight?: number
|
package/src/usePreventScroll.ts
CHANGED
|
@@ -126,7 +126,9 @@ function preventScrollMobileSafari() {
|
|
|
126
126
|
|
|
127
127
|
let onTouchEnd = (e: TouchEvent) => {
|
|
128
128
|
let target = e.target as HTMLElement;
|
|
129
|
-
|
|
129
|
+
|
|
130
|
+
// Apply this change if we're not already focused on the target element
|
|
131
|
+
if (willOpenKeyboard(target) && target !== document.activeElement) {
|
|
130
132
|
e.preventDefault();
|
|
131
133
|
|
|
132
134
|
// Apply a transform to trick Safari into thinking the input is at the top of the page
|
|
@@ -142,7 +144,7 @@ function preventScrollMobileSafari() {
|
|
|
142
144
|
|
|
143
145
|
let onFocus = (e: FocusEvent) => {
|
|
144
146
|
let target = e.target as HTMLElement;
|
|
145
|
-
if (
|
|
147
|
+
if (willOpenKeyboard(target)) {
|
|
146
148
|
// Transform also needs to be applied in the focus event in cases where focus moves
|
|
147
149
|
// other than tapping on an input directly, e.g. the next/previous buttons in the
|
|
148
150
|
// software keyboard. In these cases, it seems applying the transform in the focus event
|
|
@@ -229,13 +231,26 @@ function addEvent<K extends keyof GlobalEventHandlersEventMap>(
|
|
|
229
231
|
}
|
|
230
232
|
|
|
231
233
|
function scrollIntoView(target: Element) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
let
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
234
|
+
let root = document.scrollingElement || document.documentElement;
|
|
235
|
+
while (target && target !== root) {
|
|
236
|
+
// Find the parent scrollable element and adjust the scroll position if the target is not already in view.
|
|
237
|
+
let scrollable = getScrollParent(target);
|
|
238
|
+
if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
|
|
239
|
+
let scrollableTop = scrollable.getBoundingClientRect().top;
|
|
240
|
+
let targetTop = target.getBoundingClientRect().top;
|
|
241
|
+
if (targetTop > scrollableTop + target.clientHeight) {
|
|
242
|
+
scrollable.scrollTop += targetTop - scrollableTop;
|
|
243
|
+
}
|
|
239
244
|
}
|
|
245
|
+
|
|
246
|
+
target = scrollable.parentElement;
|
|
240
247
|
}
|
|
241
248
|
}
|
|
249
|
+
|
|
250
|
+
function willOpenKeyboard(target: Element) {
|
|
251
|
+
return (
|
|
252
|
+
(target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type)) ||
|
|
253
|
+
target instanceof HTMLTextAreaElement ||
|
|
254
|
+
(target instanceof HTMLElement && target.isContentEditable)
|
|
255
|
+
);
|
|
256
|
+
}
|