From 6155f0cc4321e1d15bd043276e4cc600c26f8820 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Wed, 4 Dec 2024 20:28:06 -0800 Subject: [PATCH] fix: Remove onTouchEnd handler in iOS usePreventScroll --- .../overlays/src/usePreventScroll.ts | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/packages/@react-aria/overlays/src/usePreventScroll.ts b/packages/@react-aria/overlays/src/usePreventScroll.ts index 08948f180c7..50176e84979 100644 --- a/packages/@react-aria/overlays/src/usePreventScroll.ts +++ b/packages/@react-aria/overlays/src/usePreventScroll.ts @@ -139,24 +139,7 @@ function preventScrollMobileSafari() { } }; - let onTouchEnd = (e: TouchEvent) => { - let target = e.target as HTMLElement; - - // Apply this change if we're not already focused on the target element - if (willOpenKeyboard(target) && target !== document.activeElement) { - e.preventDefault(); - setupStyles(); - - // Apply a transform to trick Safari into thinking the input is at the top of the page - // so it doesn't try to scroll it into view. When tapping on an input, this needs to - // be done before the "focus" event, so we have to focus the element ourselves. - target.style.transform = 'translateY(-2000px)'; - target.focus(); - requestAnimationFrame(() => { - target.style.transform = ''; - }); - } - + let onTouchEnd = () => { if (restoreScrollableStyles) { restoreScrollableStyles(); } @@ -167,10 +150,8 @@ function preventScrollMobileSafari() { if (willOpenKeyboard(target)) { setupStyles(); - // Transform also needs to be applied in the focus event in cases where focus moves - // other than tapping on an input directly, e.g. the next/previous buttons in the - // software keyboard. In these cases, it seems applying the transform in the focus event - // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️ + // Apply a transform to trick Safari into thinking the input is at the top of the page + // so it doesn't try to scroll it into view. target.style.transform = 'translateY(-2000px)'; requestAnimationFrame(() => { target.style.transform = '';