@react-aria/overlays 3.31.1 → 3.31.2
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/ariaHideOutside.main.js +52 -1
- package/dist/ariaHideOutside.main.js.map +1 -1
- package/dist/ariaHideOutside.mjs +53 -2
- package/dist/ariaHideOutside.module.js +53 -2
- package/dist/ariaHideOutside.module.js.map +1 -1
- package/dist/calculatePosition.main.js +28 -4
- package/dist/calculatePosition.main.js.map +1 -1
- package/dist/calculatePosition.mjs +28 -4
- package/dist/calculatePosition.module.js +28 -4
- package/dist/calculatePosition.module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useCloseOnScroll.main.js +2 -2
- package/dist/useCloseOnScroll.main.js.map +1 -1
- package/dist/useCloseOnScroll.mjs +3 -3
- package/dist/useCloseOnScroll.module.js +3 -3
- package/dist/useCloseOnScroll.module.js.map +1 -1
- package/dist/useOverlay.main.js +5 -3
- package/dist/useOverlay.main.js.map +1 -1
- package/dist/useOverlay.mjs +5 -3
- package/dist/useOverlay.module.js +5 -3
- package/dist/useOverlay.module.js.map +1 -1
- package/dist/useOverlayPosition.main.js +6 -5
- package/dist/useOverlayPosition.main.js.map +1 -1
- package/dist/useOverlayPosition.mjs +7 -6
- package/dist/useOverlayPosition.module.js +7 -6
- package/dist/useOverlayPosition.module.js.map +1 -1
- package/dist/usePreventScroll.main.js +9 -4
- package/dist/usePreventScroll.main.js.map +1 -1
- package/dist/usePreventScroll.mjs +10 -5
- package/dist/usePreventScroll.module.js +10 -5
- package/dist/usePreventScroll.module.js.map +1 -1
- package/package.json +12 -11
- package/src/ariaHideOutside.ts +81 -2
- package/src/calculatePosition.ts +27 -5
- package/src/useCloseOnScroll.ts +3 -3
- package/src/useOverlay.ts +4 -3
- package/src/useOverlayPosition.ts +6 -5
- package/src/usePreventScroll.ts +13 -7
package/src/usePreventScroll.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {chain, getScrollParent, isIOS, isScrollable, useLayoutEffect, willOpenKeyboard} from '@react-aria/utils';
|
|
13
|
+
import {chain, getActiveElement, getEventTarget, getScrollParent, isIOS, isScrollable, useLayoutEffect, willOpenKeyboard} from '@react-aria/utils';
|
|
14
14
|
|
|
15
15
|
interface PreventScrollOptions {
|
|
16
16
|
/** Whether the scroll lock is disabled. */
|
|
@@ -88,18 +88,22 @@ function preventScrollStandard() {
|
|
|
88
88
|
// by preventing default in a `touchmove` event. This is best effort: we can't prevent default when pinch
|
|
89
89
|
// zooming or when an element contains text selection, which may allow scrolling in some cases.
|
|
90
90
|
// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
|
|
91
|
-
// 4. When focus moves to an input, create an off screen input and focus that temporarily. This prevents
|
|
91
|
+
// 4. When focus moves to an input, create an off screen input and focus that temporarily. This prevents
|
|
92
92
|
// Safari from scrolling the page. After a small delay, focus the real input and scroll it into view
|
|
93
93
|
// ourselves, without scrolling the whole page.
|
|
94
94
|
function preventScrollMobileSafari() {
|
|
95
|
+
// Set overflow hidden so scrollIntoViewport() (useSelectableCollection) sees isScrollPrevented and
|
|
96
|
+
// scrolls only scroll parents instead of calling native scrollIntoView() which moves the window.
|
|
97
|
+
let restoreOverflow = setStyle(document.documentElement, 'overflow', 'hidden');
|
|
98
|
+
|
|
95
99
|
let scrollable: Element;
|
|
96
100
|
let allowTouchMove = false;
|
|
97
101
|
let onTouchStart = (e: TouchEvent) => {
|
|
98
102
|
// Store the nearest scrollable parent element from the element that the user touched.
|
|
99
|
-
let target = e
|
|
103
|
+
let target = getEventTarget(e) as Element;
|
|
100
104
|
scrollable = isScrollable(target) ? target : getScrollParent(target, true);
|
|
101
105
|
allowTouchMove = false;
|
|
102
|
-
|
|
106
|
+
|
|
103
107
|
// If the target is selected, don't preventDefault in touchmove to allow user to adjust selection.
|
|
104
108
|
let selection = target.ownerDocument.defaultView!.getSelection();
|
|
105
109
|
if (selection && !selection.isCollapsed && selection.containsNode(target, true)) {
|
|
@@ -116,7 +120,7 @@ function preventScrollMobileSafari() {
|
|
|
116
120
|
|
|
117
121
|
// If this is a focused input element with a selected range, allow user to drag the selection handles.
|
|
118
122
|
if (
|
|
119
|
-
'selectionStart' in target &&
|
|
123
|
+
'selectionStart' in target &&
|
|
120
124
|
'selectionEnd' in target &&
|
|
121
125
|
(target.selectionStart as number) < (target.selectionEnd as number) &&
|
|
122
126
|
target.ownerDocument.activeElement === target
|
|
@@ -162,7 +166,7 @@ function preventScrollMobileSafari() {
|
|
|
162
166
|
};
|
|
163
167
|
|
|
164
168
|
let onBlur = (e: FocusEvent) => {
|
|
165
|
-
let target = e
|
|
169
|
+
let target = getEventTarget(e) as HTMLElement;
|
|
166
170
|
let relatedTarget = e.relatedTarget as HTMLElement | null;
|
|
167
171
|
if (relatedTarget && willOpenKeyboard(relatedTarget)) {
|
|
168
172
|
// Focus without scrolling the whole page, and then scroll into view manually.
|
|
@@ -183,7 +187,8 @@ function preventScrollMobileSafari() {
|
|
|
183
187
|
let focus = HTMLElement.prototype.focus;
|
|
184
188
|
HTMLElement.prototype.focus = function (opts) {
|
|
185
189
|
// Track whether the keyboard was already visible before.
|
|
186
|
-
let
|
|
190
|
+
let activeElement = getActiveElement();
|
|
191
|
+
let wasKeyboardVisible = activeElement != null && willOpenKeyboard(activeElement);
|
|
187
192
|
|
|
188
193
|
// Focus the element without scrolling the page.
|
|
189
194
|
focus.call(this, {...opts, preventScroll: true});
|
|
@@ -200,6 +205,7 @@ function preventScrollMobileSafari() {
|
|
|
200
205
|
);
|
|
201
206
|
|
|
202
207
|
return () => {
|
|
208
|
+
restoreOverflow();
|
|
203
209
|
removeEvents();
|
|
204
210
|
style.remove();
|
|
205
211
|
HTMLElement.prototype.focus = focus;
|