question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent clicks when dropping scrollbar handle

See original GitHub issue

Describe the bug Wasn’t sure if I should raise this as a bug report or a feature request.

When the overlay scrollbar handle is dropped, a click event also fires. I think this is different from native scrollbars (I believe) and is undesired in most cases I think.

Let’s say I have a list of items, like a playlist on Spotify. You can select tracks in the playlist by clicking on them. If I now drag the overlay scrollbar and release it either on top of body or on top of the handle itself, a click event is also fired. The playlist is built to clear selection of it’s tracks when a user clicks outside of the playlist. This is a common pattern and often used to close modals when a user clicks outside:

// Inside some component
document.body.addEventListener(('click') => {
  // did click happen outside me?
  // if yes, do some state clean-up (like closing modal or clearing selection)
})

In our case I worked around this by disabling pointer-events on body and the handle while it’s being dragged.

// Prevent clicks on body and scrollbar handle when dragging and dropping the handle.
// We for example don't want to clear the selected tracks in a playlist when
// the scrollbar handle is dropped. The .os-dragging class is only applied
// while the overlay scrollbars are being dragged with the mouse.
.os-dragging,
.os-dragging .os-scrollbar-handle {
  pointer-events: none !important;
}

Happy to fill in a js-fiddle and the rest of the steps in the template later if this is not clear enough. I don’t have time right now


To Reproduce Steps to reproduce the behavior:

  1. Go to ‘…’
  2. Click on ‘…’
  3. Scroll down to ‘…’
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Examples Please create a small example of the bug. To do this you can use online platforms like JSFiddle, CodeSandbox or StackBlitz. You can also create a separate Github repository which I can clone.

Environment

  • Used Operating System(s):
  • Used Browser(s) (with version):

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tryggvigycommented, Aug 3, 2020

Just tested this in 1.13.0, works great. Thanks!

1reaction
KingSoracommented, Aug 2, 2020

Implemented in v1.13.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent clicking scrollbar from triggering .blur - Stack Overflow
The problem is .blur() triggers when the user clicks the scroll bar and the menu closes. I have an example of the menu...
Read more >
Show scroll bars in Word or Excel - Microsoft Support
Under Windows Settings, scroll down, and then click Ease of Access > Display. Scroll down, and then set Automatically hide scroll bars in...
Read more >
How to fight the <body> scroll. First of all - Medium
overflow:hidden will remove the scrollbars (they are hidden), and block the scroll, as long this overflow mode is not scrollable. This is how...
Read more >
blur event is called for input when clicked on div scrollbar
A simple workaround is to preventDefault whenever the mouse down is inside a scrollbar. ... // preventing the default still allows the scroll,...
Read more >
scrollbar handled by drag and drop | Infragistics Forums
How can i disable the drag and drop behavior if I just want to drag the scroll bar? Or is there a way...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found