-
Notifications
You must be signed in to change notification settings - Fork 80
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.preventDefault() in onClick does not work in this use case #39
Comments
I tried using |
Hello. Could you please provide your initialization code? I cannot reproduce it yet |
I have the same issue. In my case this happens when the elements of the scollable container have an onClick property. <div class="scroll-element" onclick={DoSomething}></div> They seem to trigger first before the onClick method from scrollBooster is being triggered and therefore don't seem to be preventable. Adding As a workaround without having to alter the source code this works as well: const viewport = document.querySelector('.viewport')
const sb = new ScrollBooster({
//options
viewport: viewport,
onClick: (state, event) => {
// your onclick logic
}
})
// add this to prevent any underlying clicks from happening
viewport.addEventListener('click', sb.events.click, true) |
Thank you, works! |
Came here to make the same suggestion, that the viewport should probably be capturing events and handling them first with capture: true The click handler correctly detects whether a scroll was initiated or not, and if dragging stops the event Lines 595 to 598 in 31ee2d1
The problem is that when addEventListener doesn't have capture set, the click event is dispatched to listeners on elements lower down in the DOM tree inside the viewport first (eg the link you clicked on, or something). But we need the scrollbooster click handler called first to check if it's a drag or not. |
Use case: http://i.venner.io/2020-03-12_20-03-12.webm
I fixed it by changing:
scrollbooster/src/index.js
Line 518 in 2713dd6
to
However, I am not sure of the implications this would have on other users.
The text was updated successfully, but these errors were encountered: