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

Handle click prevention on drag automatically #423

Merged
merged 1 commit into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions packages/embla-carousel-docs/src/content/pages/api/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Get slide indexes not visible in the carousel viewport. Honors the [inViewThresh
Parameters: <BrandPrimaryText>`none`</BrandPrimaryText>
Returns: <BrandSecondaryText>`boolean`</BrandSecondaryText>

**Note!** This method is **deprecated**. From **v7.0.8** and up this is handled automatically by Embla.

For touch pointers, this method will return `false` when the gesture is a drag move or if the carousel is clicked during scroll. For mouse pointers, this method will only return `false` when the gesture is a drag move.

### reInit
Expand Down
8 changes: 6 additions & 2 deletions packages/embla-carousel/src/components/DragHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function DragHandler(
.add(node, 'mousedown', down)
.add(node, 'touchcancel', up)
.add(node, 'contextmenu', up)
.add(node, 'click', click, nonPassiveEvent)
.add(node, 'click', click, true)
}

function addInteractionEvents(): void {
Expand Down Expand Up @@ -166,9 +166,13 @@ export function DragHandler(
}

function click(evt: MouseEvent): void {
if (preventClick) evt.preventDefault()
if (preventClick) {
evt.stopPropagation()
evt.preventDefault()
}
}

// DEPRECATED - Remove in v8 because handled automatically
function clickAllowed(): boolean {
return !preventClick
}
Expand Down