Skip to content
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

Added cancelOnLeave option #69

Merged
merged 2 commits into from
Nov 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/keen-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ function KeenSlider(initialContainer, initialOptions = {}) {
e.preventDefault()
})
eventAdd(container, 'mousedown', eventDragStart)
eventAdd(container, 'mousemove', eventDrag)
eventAdd(container, 'mouseleave', eventDragStop)
eventAdd(container, 'mouseup', eventDragStop)
eventAdd(options.cancelOnLeave ? container : window, 'mousemove', eventDrag)
if (options.cancelOnLeave) eventAdd(container, 'mouseleave', eventDragStop)
eventAdd(window, 'mouseup', eventDragStop)
Copy link
Contributor

@roderickhsiao roderickhsiao Sep 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this change is intentional? this is changing the existing behavior as the mouseup event now binding to window regardless of options.cancelOnLeave option, which previously bind to the container.

Some of our use case which manually handles tap (mouseup) on the slide and programmatically calls slider.next/slider.prev (v5), and this behavior breaks the use case as the timing for eventDragStop changes (window vs container).

eventAdd(container, 'touchstart', eventDragStart, {
passive: true,
})
Expand Down Expand Up @@ -700,6 +700,7 @@ function KeenSlider(initialContainer, initialOptions = {}) {
mode: 'snap',
rtl: false,
rubberband: true,
cancelOnLeave: true
}

const pubfuncs = {
Expand Down