-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
ClickAwayListener triggers on clicking browser scrollbar #15724
Comments
We would need to detect in the ClickAwayListener if the click happened on the scrollbars. I don't know if this is possible. Could be so kind and create a playground with a Menu with just many items so that we can verify whether this is an issue with this particular demo or the base Menu. |
I have checked code in ClickAwayListener. No condition is written to handle scrollbar click |
@Umerbhat I have found a similar thread on kentor/react-click-outside#9. It's something Bootstrap handles well. What do you think of this change? diff --git a/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js b/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
index 604c02a75..f4347e60c 100644
--- a/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
+++ b/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
@@ -40,6 +40,11 @@ function ClickAwayListener(props) {
const handleClickAway = React.useCallback(
event => {
+ // Ignore click events on the scrollbar.
+ if (event.offsetX > event.target.clientWidth || event.offsetY > event.target.clientHeight) {
+ return;
+ }
+
// Ignore events that have been `event.preventDefault()` marked.
if (event.defaultPrevented) {
return; |
Yes, I had checked it before that bootstrap handles it well. It is a great solution to find whether we clicked on the scrollbar. However, it works only for inner scrollbars. For outer scrollbars like in macOS, it fails |
@Umerbhat Correct, this would work: diff --git a/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js b/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
index 604c02a75..b1273b25a 100644
--- a/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
+++ b/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
@@ -64,6 +64,15 @@ function ClickAwayListener(props) {
const doc = ownerDocument(node);
+ // Ignore click events on the scrollbar.
+ if (
+ event.offsetX > event.target.clientWidth ||
+ event.offsetY > event.target.clientHeight ||
+ event.target === doc.querySelector('html')
+ ) {
+ return;
+ }
+
if (
doc.documentElement &&
doc.documentElement.contains(event.target) && But something is off, I can't figure out how bootstrap, reactstrap and react-bootstrap have a correct behavior without any explicit code 😮. |
Found it 💡 ! It has to do with using onClick (OK) vs onMouseDown / onMouseUp (KO). |
Got it! it differs on Event. Well, I had a solution. It works for chrome macOS
|
@Umerbhat The fewer layout math we can do, the better. |
@Umerbhat Do you want to move forward with the |
yes, it is fine to do for document's scrollbar. In my case dropdown is inside scrollable divisions, we need to handle it. I think these two will work fine together.
Thus, handling click on all visible scrollbars. |
and the best |
Ok, so maybe the best option is to start by changing the default event listener? |
One thing I noticed is that no onClick is fired if I click on a scrollbar. Only mousedown + mouseup. So the easiest solution is to just use |
Yeah, exactly, change it to use onClick +1. |
Though I have a hard time finding this in the spec. We need to verify if this works on all browsers. |
I am glad to know this, the only difference in bootstrap. Great Work! |
@Umerbhat Do you want to submit a pull request here to fix the default value? |
@oliviertassinari Sure. Thanks for the honour. Default props |
Expected Behavior 🤔
Current Behavior 😯
Steps to Reproduce 🕹
Link: https://material-ui.com/demos/menus/#menulist-composition
Context 🔦
When the menu has too many items if the user wants to select the last item, he needs to scroll. But this issue blocks a user from selecting the last options of the menu.
The text was updated successfully, but these errors were encountered: