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

fix carousel item children with click handlers #2256

Conversation

evayde
Copy link
Contributor

@evayde evayde commented Nov 4, 2024

Don't trigger the click event while dragging.

Fixes #2196

Copy link

vercel bot commented Nov 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
shoelace ✅ Ready (Inspect) Visit Preview Nov 5, 2024 10:30am

@claviska
Copy link
Member

claviska commented Nov 4, 2024

Thanks for the PR. Unfortunately, this doesn't seem to prevent the click when dragging an anchor element, e.g.:

<sl-carousel-item>
  <a href="about:blank" target="_blank">
    <img
      alt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"
      src="/assets/examples/carousel/mountains.jpg"
    />
  </a>
</sl-carousel-item>

@evayde
Copy link
Contributor Author

evayde commented Nov 5, 2024

My fail, I forgot to add preventDefault for the anchors. I'd love to write a test for this aswell, unfortunately, our drag-function does not trigger the click event (or the anchor). :(

@claviska
Copy link
Member

claviska commented Nov 5, 2024

Thanks again for the PR. The solution was almost there, but sometimes clicking on the anchor wouldn't open it because we're only checking for this.dragging, so it felt unreliable. (Every 2-3 clicks it wouldn't drag or open the link for me.)

I added a check for the start x/y position to compare it to the mouse position when the click occurs in #2259 and it feels pretty solid.

@claviska claviska closed this Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interactive elements are activated after dragging in <sl-carousel mouse-dragging>
2 participants