onWheel Stop bubbling is not happening.
See original GitHub issueMy Target: I am having a div which scrolls. But on coming to the top or the bottom after the scrolling the div, the scrolling starts happening on the entire page itself which I don’t want. I think it’s happening due to event propagation, so I am trying to stop in following manner.
My Implementation: I am using “extends Component (es6 way)” to create my components. And I’ve put onWheel event listener as
return ( <div className='scroll-box-list' onWheel = {(e)=>{console.log('Scrolling Me..'); e.stopPropagation();}}> <OtherThings /> </div> );
It’s consoling out ‘Scrolling Me’ fine but I am not able to stop propagating this event to the parent. Not sure why stopPropagation is not happening exactly or whether this issue is happening because of propagation
I don’t want to use libraries which used mixins, so please don’t suggest me this way.
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
React JS: onWheel bubbling stopPropagation not working
I think it's happening due to event propagation, so I am trying to stop in following manner. My Implementation: I am using "extends...
Read more >React 17 stops event bubbling in scroll event - Saeloun Blog
In React 17 the scroll event no longer bubbles to align with browser's behavior.
Read more >How to stop the wheel event propagation - Esri Community
When I use wheel to zoom in/out, and the outer page has scroll bar - the wheel event bubbles to this outer page...
Read more >Element: wheel event - Web APIs | MDN
The wheel event fires when the user rotates a wheel button on a pointing device (typically a mouse). This event replaces the non-standard ......
Read more >SyntheticEvent - React
The synthetic events are different from, and do not map directly to, the browser's ... false from an event handler will no longer...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I hit this issue too, and eventually found this blog post explaining the root cause: https://medium.com/@ericclemmons/react-event-preventdefault-78c28c950e46
Using the
nativeEvent
didn’t work for me either, but it did work to use aref
on the element and manually doref.current.addEventListener("wheel", (event) => event.stopPropagation())
Hi , I used the event.preventDefault in React and it can work, The demo https://jsfiddle.net/monkindey/9kobyd2w/, I extract the logic code to be a npm package and it may be easy to use.
Hope it helps.