Skip to content
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

Event should not trigger on clicking browser scrollbar #19

Open
udayakumarswamy opened this issue Nov 28, 2018 · 9 comments
Open

Event should not trigger on clicking browser scrollbar #19

udayakumarswamy opened this issue Nov 28, 2018 · 9 comments

Comments

@udayakumarswamy
Copy link

No description provided.

@ljharb
Copy link
Collaborator

ljharb commented Nov 28, 2018

I’m not sure what you mean - scrolling certainly shouldn’t trigger a click, since the scroll bar is entirely outside of the viewport (it’s not a DOM element). Can you provide a repro case?

@udayakumarswamy
Copy link
Author

@ljharb,
There is a modal popup with window scroll, i want close modal pop on outside click not like on click scrollbar with up/down arrows.

@ljharb
Copy link
Collaborator

ljharb commented Nov 29, 2018

right - i'm surprised to hear that clicking on any part of the scrollbar would create a click event. That's not been my experience. Can you provide a repro case?

@Hurtak
Copy link

Hurtak commented Mar 10, 2019

I somewhat vaguely remember that back in the day adding click handler to window might register events from scrollbar clicking. Adding the event to document solved this. But this was few years back so my memory is fuzzu, might still happen on Windows/Linux on some browsers, cant reproduce on MacOS.

@udayakumarswamy
Copy link
Author

udayakumarswamy commented Mar 11, 2019

@ljharb and @Hurtak Repo case:
I have a div with some events inside of that, which will appear on hover image.
So, I would like to get an event on clicking outside of the div. I'm able to get it. But, the event should not fire on a browser scrolling bar click.

@forciwc
Copy link

forciwc commented Mar 12, 2019

I have this same issue that I experienced when using react-dates. Here is a repo case: http://airbnb.io/react-dates. For the default date range picker, clicking the scroll bar closes the date range picker with a mouse down / mouse up event on the entire document. A similar issue existed in bootstrap for modals closing on mouse down. twbs/bootstrap#14263. It seems like scroll bars receive a mouse down / mouse up event, but not a click event.

@ljharb
Copy link
Collaborator

ljharb commented Mar 12, 2019

If this is a browser bug, then the only way we can get around it is if there’s a way to determine that the event was generated from clicking on the scrollbar. If there is, then this can be fixed; if not, not.

@forciwc
Copy link

forciwc commented Mar 12, 2019

The only way I can guess is to check if the event.target is the html tag (the entire document) or if the parent element is undefined. Specifically this line in the onMouseDown function:

const isDescendantOfRoot = this.childNode && this.childNode.contains(e.target) && e.target.parentElement !== null;
It is my understanding there should be no way to target the html tag as the body should intercept all events.

Alternatively, addEventListener calls could be updated to listen on document.body, which should also prevent the scrollbar target from intercepting. I changed the code locally, and both options worked for me.

@ljharb
Copy link
Collaborator

ljharb commented Mar 12, 2019

Hmm - if in fact that's the case (that the target can't ever be the html tag except in this case), and we can verify that in all supported browsers, then that seems like a good approach.

It doesn't seem like a good idea to install more event listeners on the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants