Embla-carousel: Prevent click event on child element when dragging

Created on 3 Oct 2019  路  11Comments  路  Source: davidcetinkaya/embla-carousel

I created a carousel and added my custom clickable elements inside. The problem is when I drag the carousel and then I mouseup, click event is triggered which is not the desired action.

feature request good first issue resolved

All 11 comments

Hi Alex (@alexcoroza),

Thanks for taking time to open this issue. Would you mind forking this CodeSandbox to demonstrate the issue and what you want to achieve? It's much easier for me to troubleshoot and help you that way. Thank you for your patience.

Kindly,
David

Oooh, Didnt expect this, you responded so quick. Here is the example scenario:

Sample Code

When you drag to change slides and then you mouseup on top of a slide, the click event is triggered. Actually Im using this library in my angular app so the sample codes in sandbox is quite different(but they show the same problem).

I tried many javascript drag scroll carousel libraries they have all this kind of issue except for the ngx-drag-scroll(though its laggy). As of now I'm just showing an inivisible overlay whenever .on('scrolling') is called then hide it when finished, just to prevent the child element's click event

Hello Alex (@alexcoroza),

Thank you for the sample code 馃憤. Just want to make sure that I understand you correctly before we start discussing how to solve this issue:

  1. Do you want to prevent the click event from triggering if dragging has occurred?
  2. Or do you actually want to prevent the click event from triggering if carousel is scrolling?

All the best,
David

Yes the question 1. I just want to prevent the click event only when dragging.

Hello Alex (@alexcoroza),
I'm happy to announce that I've released a click check for Embla 馃帀:

embla.clickAllowed()

Please read about it in the release description. You can see it in action in this CodeSandbox. This method is an opt-in feature and here is how it works: It returns false if:

Mouse Pointers

  • Mouse drags the carousel.

Touch Pointers

  • Touch drags the carousel.
  • Carousel is in motion (i.e. is scrolling).

Otherwise it will return true. Try v2.6.1 for this feature. I'd very much appreciate your feedback on this and if it solves your issue. Thank you in advance!

Kindly,
David

Hi Alex (@alexcoroza),

I鈥檓 curious if you鈥檝e had the chance to try this yet?

Kindly,
David

Hello again Alex (@alexcoroza),
I'm closing this due to lack of response. Feel free to reopen this issue if you don't think it's resolved.

Thank you for your feature request!
David

Hey @davidcetinkaya this is exactly what I need but I'm struggling to figure out how to implement it while using the react version. Any chance you could provide a bit of guidance?

Thanks so much for you hard work in this, it has the smoothest animations I've found for a carousel library!

Hi @coopemor,

I would be happy to help. In order to do so I need additional details. Are you using React hooks or class based components?

Kindly,
David

Amazing! Thank you @davidcetinkaya I'm using hooks in my design.

Hello @coopemor,

Your question is related to the Embla Carousel React, so I decided to create a new issue there. Just follow this link and we'll continue this conversation there.

Thanks!
David

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jamesdbruner picture jamesdbruner  路  3Comments

S1SYPHOS picture S1SYPHOS  路  6Comments

nikrowell picture nikrowell  路  6Comments

krikienoid picture krikienoid  路  6Comments

nikrowell picture nikrowell  路  7Comments