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.

onClick event being fired during drag

See original GitHub issue

Bug is related to

  • The Vanilla JavaScript version
  • The React version
  • The Embla Carousel core (all versions)
  • Documentation website
  • Other

Embla Carousel version

  • 4.3.1 (older versions as well)

Describe the bug

When dragging a slide and letting go, it triggers a click event when the drag is released. This can be problematic for carousel items that have click handlers on them.

A common thing people will do with carousel items is attach an click handler to trigger a specific behavior such as:

  • opening a modal
  • redirecting to another page in the app
  • etc…

https://user-images.githubusercontent.com/6743796/113911974-77be2680-978f-11eb-9535-5a7731221cdf.mp4

CodeSandbox

Steps to reproduce

  1. Add click handler on a carousel item
  2. Drag the item and release

Expected behavior

The api should be able to distinguish between a drag event and an on click event.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
davidjerlekecommented, May 18, 2021

Hi @cliffordfajardo,

I recently released the search feature on the documentation website. I went with Algolia Docsearch.

Cheers, David

1reaction
davidjerlekecommented, Apr 7, 2021

Hi Clifford (@cliffordfajardo),

Thank you for your question. This is not a bug.

Have you read about the opt-in clickAllowed method in the docs?

Maybe this explanation from issue #132 which is related to this will help.

Let me know if it helps.

Best, David

Read more comments on GitHub >

github_iconTop Results From Across the Web

onClick event being fired during drag · Issue #174 - GitHub
When dragging a slide and letting go, it triggers a click event when the drag is released. This can be problematic for carousel...
Read more >
drag event is being fired on click - javascript - Stack Overflow
dragstart fires when the user clicks the element, while dragmove fires on every update on the element position. The problem is that dragmove...
Read more >
ondrag Event - W3Schools
The ondrag event occurs when an element or text selection is being dragged. Drag and drop is a common feature in HTML. It...
Read more >
Introduction to browser events - The Modern JavaScript Tutorial
Here's a list of the most useful DOM events, just to take a look at: Mouse events: click – when the mouse clicks...
Read more >
ASP.NET Core Blazor event handling - Microsoft Learn
Implement drag and drop in Blazor apps using JS interop with HTML Drag ... An onclick event occurring in the child component is...
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