-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cancel outside click behavior on touch devices when scrolling #3266
Conversation
When on a touch device, then the `touchend` event will fire, even if you scrolled a bit and scrolling was your intention. This now tracks that touches were at least 30px apart in either the X or Y direction. If that's the case, then we do not consider it an outside click.
This now takes the new `enabled` value into account.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
useEffect( | ||
process.env.NODE_ENV === 'test' | ||
? () => { | ||
enabledRef.current = isTopLayer | ||
} | ||
: () => { | ||
requestAnimationFrame(() => { | ||
enabledRef.current = isTopLayer | ||
}) | ||
}, | ||
[isTopLayer] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linked issue was expected behavior, since then we've also restructured some of this logic and this doesn't happen anymore.
The issue we were seeing was that opening a <Dialog />
by setting state in an onClick
, registered a click
listener on the window
and immediately triggered it so the <Dialog />
was immediately closed.
"vue": "^3.4.27", | ||
"vue-flatpickr-component": "^9.0.5", | ||
"vue-router": "^4.0.0" | ||
"vue-router": "^4.3.2" | ||
}, | ||
"devDependencies": { | ||
"@floating-ui/vue": "^1.0.2", | ||
"@vitejs/plugin-vue": "^3.0.3", | ||
"vite": "^3.0.0" | ||
"@vitejs/plugin-vue": "^5.0.5", | ||
"vite": "^5.2.12" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed that playgrounds for Vue were broken, bumping these dependencies fixed the playground again.
This PR improves the outside click behavior on touch devices.
Before this change, if a
<Menu />
or<Dialog />
was open, then "scrolling" or "swiping" your finger on the screen would close the<Menu />
or<Dialog />
respectively.This is because we also checked for
touchend
events (which are fired when you lift your finger). Right now, we will make sure that your finger has to move at least some amount (set it to 30px for now, which felt good while testing on mobile devices) in order to cancel the outside click behaviour. If you didn't move within 30px then we consider it an outside click.Now, scrolling doesn't close the component, but a tap (
touchend
) will close it as expected.Fixes: #3038