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

[Bug]: AutoScroll position jumps when clicked and dragged #764

Open
5 of 14 tasks
jasonk16 opened this issue Feb 24, 2024 · 7 comments
Open
5 of 14 tasks

[Bug]: AutoScroll position jumps when clicked and dragged #764

jasonk16 opened this issue Feb 24, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@jasonk16
Copy link

jasonk16 commented Feb 24, 2024

Which variants of Embla Carousel are you using?

  • embla-carousel (Core)
  • embla-carousel-react
  • embla-carousel-vue
  • embla-carousel-svelte
  • embla-carousel-autoplay
  • embla-carousel-auto-scroll
  • embla-carousel-solid
  • embla-carousel-auto-height
  • embla-carousel-class-names
  • embla-carousel-docs (Documentation)
  • embla-carousel-docs (Generator)

Steps to reproduce

I've recently updated the carousel to version 8.0.0. The carousel shifts its position when I click and drag the carousel, with autoscroll enabled. Based on my observation so far, it tends to happen if the mouse has entered the carousel, where it stops scrolling, and the user clicks and drags. It does not happen when my mouse quickly enters and drags the carousel.

embla.2.mp4

Expected Behavior

Carousel should not shift its position when clicked and dragged.

Additional Context

I'm using Nextjs 14 with app router.

What browsers are you seeing the problem on?

Chrome

Version

8.0.0

CodeSandbox

https://codesandbox.io/p/sandbox/embla-carousel-auto-scroll-react-forked-lkvshs?file=%2Fsrc%2Fjs%2FEmblaCarousel.tsx

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
  • I agree to follow this project's Contributing Guidelines for bug reports
@jasonk16 jasonk16 added the bug Something isn't working label Feb 24, 2024
@davidjerleke
Copy link
Owner

Hi @jasonk16,

Thanks for your bug report. Have you seen the example in the docs? Can you reproduce it there? If no, please check how to work with the plugin there.

Best,
David

@jasonk16
Copy link
Author

jasonk16 commented Feb 24, 2024

Thanks for your quick reply @davidjerleke. I've reproduced the jumpyness based on the example here, I've just changed the individual items to suit my needs, which is an image container.

@davidjerleke
Copy link
Owner

davidjerleke commented Feb 24, 2024

@jasonk16 thanks! I'll investigate what's going on when possible.

This might be related to anchor tags being elements that can receive focus. If my assumption is correct, the carousel jumps to the slide that is active when the focus event is triggered from a click.

Best,
David

@jasonk16
Copy link
Author

Your assumption is correct. I've just tried removing the anchor tags from the cards and it does not jump anymore. Perhaps I could use onClick on divs as a workaround temporarily, but long term I guess its not a good html semantics if those cards are links.

I also tried nesting the anchor tag within the div but I guess the focus still triggers on click. Let me know if theres anything you'd need my help on. Thanks again!

Repository owner deleted a comment from MuhamedAyoub Feb 25, 2024
@davidjerleke
Copy link
Owner

Perhaps I could use onClick on divs as a workaround temporarily, but long term I guess it's not a good html semantics if those cards are links.

@jasonk16 you're right about that. It's not good semantics so a solution for this is needed. I'm working on a new option called watchFocus which will enable you to either disable/enable the auto focus feature with a boolean. Alternatively, you will be able to pass your own callback to control when Embla should focus or not: Similar to watchDrag, watchResize and watchSlides.

Unfortunately, until then, you'll have to stick with the hacky solution you mentioned.

Best,
David

@jasonk16
Copy link
Author

Oh yeah, something like watchFocus would be beneficial. Thanks a lot for coming up with a fix. I'll just go with the hacky solution for now but happy to help if you'd need me to test anything.

@davidjerleke
Copy link
Owner

Thanks @jasonk16. It would definitely help if you wouldn’t mind testing as soon as I have a draft ready. I’ll let you know when I have something 👍🏻.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants