@react-aria/overlays 3.6.3 → 3.7.3
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 +33 -7
- package/dist/main.js.map +1 -1
- package/dist/module.js +33 -7
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/useCloseOnScroll.ts +3 -2
- package/src/useOverlay.ts +35 -3
- package/src/useOverlayTrigger.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/overlays",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.3",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/i18n": "^3.3.
|
|
22
|
-
"@react-aria/interactions": "^3.
|
|
23
|
-
"@react-aria/utils": "^3.
|
|
24
|
-
"@react-aria/visually-hidden": "^3.2.
|
|
25
|
-
"@react-stately/overlays": "^3.1.
|
|
26
|
-
"@react-types/button": "^3.
|
|
27
|
-
"@react-types/overlays": "^3.
|
|
21
|
+
"@react-aria/i18n": "^3.3.3",
|
|
22
|
+
"@react-aria/interactions": "^3.7.0",
|
|
23
|
+
"@react-aria/utils": "^3.10.0",
|
|
24
|
+
"@react-aria/visually-hidden": "^3.2.3",
|
|
25
|
+
"@react-stately/overlays": "^3.1.3",
|
|
26
|
+
"@react-types/button": "^3.4.1",
|
|
27
|
+
"@react-types/overlays": "^3.5.1",
|
|
28
28
|
"dom-helpers": "^3.3.1"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "896eabe5521a0349a675c4773ed7629addd4b8c4"
|
|
38
38
|
}
|
package/src/useCloseOnScroll.ts
CHANGED
|
@@ -36,8 +36,9 @@ export function useCloseOnScroll(opts: CloseOnScrollOptions) {
|
|
|
36
36
|
|
|
37
37
|
let onScroll = (e: MouseEvent) => {
|
|
38
38
|
// Ignore if scrolling an scrollable region outside the trigger's tree.
|
|
39
|
-
let target = e.target
|
|
40
|
-
|
|
39
|
+
let target = e.target;
|
|
40
|
+
// window is not a Node and doesn't have contain, but window contains everything
|
|
41
|
+
if (!triggerRef.current || ((target instanceof Node) && !target.contains(triggerRef.current))) {
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
44
|
|
package/src/useOverlay.ts
CHANGED
|
@@ -46,7 +46,9 @@ interface OverlayProps {
|
|
|
46
46
|
|
|
47
47
|
interface OverlayAria {
|
|
48
48
|
/** Props to apply to the overlay container element. */
|
|
49
|
-
overlayProps: HTMLAttributes<HTMLElement
|
|
49
|
+
overlayProps: HTMLAttributes<HTMLElement>,
|
|
50
|
+
/** Props to apply to the underlay element, if any. */
|
|
51
|
+
underlayProps: HTMLAttributes<HTMLElement>
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
const visibleOverlays: RefObject<HTMLElement>[] = [];
|
|
@@ -57,7 +59,14 @@ const visibleOverlays: RefObject<HTMLElement>[] = [];
|
|
|
57
59
|
* or optionally, on blur. Only the top-most overlay will close at once.
|
|
58
60
|
*/
|
|
59
61
|
export function useOverlay(props: OverlayProps, ref: RefObject<HTMLElement>): OverlayAria {
|
|
60
|
-
let {
|
|
62
|
+
let {
|
|
63
|
+
onClose,
|
|
64
|
+
shouldCloseOnBlur,
|
|
65
|
+
isOpen,
|
|
66
|
+
isDismissable = false,
|
|
67
|
+
isKeyboardDismissDisabled = false,
|
|
68
|
+
shouldCloseOnInteractOutside
|
|
69
|
+
} = props;
|
|
61
70
|
|
|
62
71
|
// Add the overlay ref to the stack of visible overlays on mount, and remove on unmount.
|
|
63
72
|
useEffect(() => {
|
|
@@ -80,8 +89,21 @@ export function useOverlay(props: OverlayProps, ref: RefObject<HTMLElement>): Ov
|
|
|
80
89
|
}
|
|
81
90
|
};
|
|
82
91
|
|
|
92
|
+
let onInteractOutsideStart = (e: SyntheticEvent<HTMLElement>) => {
|
|
93
|
+
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as HTMLElement)) {
|
|
94
|
+
if (visibleOverlays[visibleOverlays.length - 1] === ref) {
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
83
101
|
let onInteractOutside = (e: SyntheticEvent<HTMLElement>) => {
|
|
84
102
|
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as HTMLElement)) {
|
|
103
|
+
if (visibleOverlays[visibleOverlays.length - 1] === ref) {
|
|
104
|
+
e.stopPropagation();
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
}
|
|
85
107
|
onHide();
|
|
86
108
|
}
|
|
87
109
|
};
|
|
@@ -95,7 +117,7 @@ export function useOverlay(props: OverlayProps, ref: RefObject<HTMLElement>): Ov
|
|
|
95
117
|
};
|
|
96
118
|
|
|
97
119
|
// Handle clicking outside the overlay to close it
|
|
98
|
-
useInteractOutside({ref, onInteractOutside: isDismissable ? onInteractOutside : null});
|
|
120
|
+
useInteractOutside({ref, onInteractOutside: isDismissable ? onInteractOutside : null, onInteractOutsideStart});
|
|
99
121
|
|
|
100
122
|
let {focusWithinProps} = useFocusWithin({
|
|
101
123
|
isDisabled: !shouldCloseOnBlur,
|
|
@@ -106,10 +128,20 @@ export function useOverlay(props: OverlayProps, ref: RefObject<HTMLElement>): Ov
|
|
|
106
128
|
}
|
|
107
129
|
});
|
|
108
130
|
|
|
131
|
+
let onPointerDownUnderlay = e => {
|
|
132
|
+
// fixes a firefox issue that starts text selection https://bugzilla.mozilla.org/show_bug.cgi?id=1675846
|
|
133
|
+
if (e.target === e.currentTarget) {
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
109
138
|
return {
|
|
110
139
|
overlayProps: {
|
|
111
140
|
onKeyDown,
|
|
112
141
|
...focusWithinProps
|
|
142
|
+
},
|
|
143
|
+
underlayProps: {
|
|
144
|
+
onPointerDown: onPointerDownUnderlay
|
|
113
145
|
}
|
|
114
146
|
};
|
|
115
147
|
}
|
package/src/useOverlayTrigger.ts
CHANGED
|
@@ -40,7 +40,7 @@ export function useOverlayTrigger(props: OverlayTriggerProps, state: OverlayTrig
|
|
|
40
40
|
// Backward compatibility. Share state close function with useOverlayPosition so it can close on scroll
|
|
41
41
|
// without forcing users to pass onClose.
|
|
42
42
|
useEffect(() => {
|
|
43
|
-
if (ref.current) {
|
|
43
|
+
if (ref && ref.current) {
|
|
44
44
|
onCloseMap.set(ref.current, state.close);
|
|
45
45
|
}
|
|
46
46
|
});
|