-
Notifications
You must be signed in to change notification settings - Fork 305
fix(@toss/react): Fix the useOutsideClickEffect callback function to be called only once #355
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
Conversation
👷 Deploy request for slash-libraries pending review.Visit the deploys page to approve it
|
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.
Thank you for contributing.
I think you solved it well.
Since there is a problem with the touch device, can't we solve problem either device is touch device or not ?
IsMobileWeb
is only branching according to iOS
, android
, not processing whether it's a touch device or not.
I think you can go over things like navigator.maxTouchPoints
Can't we listen to both |
Thank you for your response. Even when I experimented with my iPad, mouse events such as �mousedown occurred when I touched it https://codesandbox.io/s/trusting-fog-6vgygn?file=/src/App.js 20231106_200311.mp4 |
Yes. As you said, branching out depending on whether it's a touch device is one of the solutions. But the problem with this approach is that there are devices like Desktop browsers support touch as well as mobile browsers. https://caniuse.com/?search=touch The summary is as follows.
What if the code changes as follows? document.addEventListener('touchstart', handleDocumentClick);
if (!isMobileWeb()) {
document.addEventListener('click', handleDocumentClick);
} |
@sa02045 useEffect(() => {
const eventType = isMobileWeb() ? 'touchstart' : 'click';
document.addEventListener(eventType, handleDocumentClick);
return () => {
document.removeEventListener(eventType, handleDocumentClick);
};
}); |
The main problem we should solve is that the callback could be called twice, not which event must be triggered. So we just make useEffect(() => {
document.addEventListener('click', handleDocumentClick);
return () => {
document.removeEventListener('click', handleDocumentClick);
};
}); |
Yes, listening to click events alone solves the problem easily. However, listening only to click events can lead to poor usability for mobile users. A click event is triggered when a finger is removed from the touchscreen. However, in a mobile environment, users often swipe the screen or drag the screen without removing their finger. This creates a "delay" in the action we want to invoke. Personally, I feel this has a lot of negative impact on usability. Therefore, I think we should consider listening to the touch event as well and fix it. |
But that's exactly why I told you that First of all, what is click? It is an action to press on and release an element with something like pointer, finger, ... But how about the touchstart event? It is triggered when you just put your fingers on a screen. It is different from the click action and it makes And you also told me about 'delay' and the swipe and drag gestures. But the gestures are also different from the click action, and they never trigger the click events. So I think it is not appropriate to call them 'delay'. |
Simply put, I would like to ask you to think more about the name of |
Overview
FIX #354
Because of the limitations on the touch event test in Testing library, no way to test was found.
Let me know if there's any other way
PR Checklist