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.

[Slider] Component doesn't allow for preventing event propagation for drag-related event handlers.

See original GitHub issue

Summary

Using <Slider> as a child of a React component that also listens for drag events, when I drag the Slider, the parent component event handlers are triggered. (I think - actually I’m a little out of my depth in terms of how these libraries are handling events and which events are being handled)

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate. To my knowledge this issue hasn’t been raised yet (although it could be related to an issue that I wouldn’t have known to search for - in which case I apologize!)

Example code

This is the most basic usage example of react-beautiful-dnd, with a list of 10 items that can be reordered. Each of these items contains a slider that shows the problem I am experiencing (that the slider’s can’t be dragged without triggering the dnd drag): https://codesandbox.io/s/recursing-nightingale-issyt?fontsize=14&hidenavigation=1&theme=dark (in the Demo.js file)

Current Behavior 😯

When trying to update the slider value by drag, the parent component event handlers are fired (see the demo). Updating the slider value by clicking works fine.

Expected Behavior 🤔

I expected that any event explicitly handled by <Slider> would not then bubble up to parent components. Or, I would like to be able to ‘manually’ prevent this by using ev.stopPropagation. However, having tried this in the onChange event handler I know that this doesn’t work. I assume that the onChange handler is an abstraction over other event handlers that I DON’T have access to?

Steps to Reproduce 🕹

The bug/behaviour (technically I’m not sure that this can be considered a bug per say) is reproduced in the codesanbox example linked to above.

Steps:

  1. Try adjusting a slider (it doesn’t work)
  2. Change isDragDisabled to true (line 83 of Demo.js), then refresh the page
  3. Dragging the slider now works

Context 🔦

I have found that disabling the ability to drag on the parent element allows me to then using the Slider. So, my current workaround is registering onMouseEnter and onMouseLeave handlers that sets a property on the parent component to disable / enable drag. But I think this is probably inefficient… since I imagine that I am rerendering the Draggable component more than I have to (I’m not 100% clear on this).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
oliviertassinaricommented, Sep 18, 2020

@zachsa The Slider has a touch-action CSS property, hence the behavior you are seeing on mobile. The issue is on desktop.

1reaction
oliviertassinaricommented, Sep 15, 2020

@brorlarsnicklas You are free to go. It’s interesting to compare the behavior with a native slider. If you could figure out what makes it work correctly in https://codesandbox.io/s/boring-platform-tkel2. It would be awesome.

Capture d’écran 2020-09-15 à 22 01 21
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Slider] Component doesn't allow for preventing event ... - GitHub
When trying to update the slider value by drag, the parent component event handlers are fired (see the demo). Updating the slider value...
Read more >
Event.stopPropagation() - Web APIs | MDN
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Read more >
How can you prevent propagation of events from a MUI (v4 ...
I have a MUI v4 Slider (specifically used as a range slider: https://v4.mui.com/components/slider/#range-slider) component inside an expandable ...
Read more >
Application Event Propagation - Salesforce Developers
If a component stops the event propagation using event. stopPropagation() , the component becomes the root node used in the default phase.
Read more >
Event Bubbling and Event Catching in JavaScript and React
Let's say we know a girl named Molly , who also happens to be not a real ... She has a single parent...
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