Skip to content

Conversation

MichaelWest22
Copy link
Collaborator

@MichaelWest22 MichaelWest22 commented Jun 27, 2025

Description

A recent change #3336 that just shipped in 2.0.5 has introduced a regression bug where if links contain elements trigger click events it now uses the contained element instead of the wrapping link to make the decision of if the click should prevent a links default navigation behavior. The fix that broke it was designed to handle situations where you listen for a click event on a higher up element causes checkboxes and other elements to lose their ability to operate with clicks if the active htmx element is a form or a link. And to fix this issue it now checks the element that was clicked for if it is a link to prevent instead of the active htmx element.

To fix this issue i've added a line to the shouldCancel link checking code to located the closest wrapping link (or the event element itself if its a link)

Also found another edge case issue this resolves that is not working in older htmx versions as well. If you place htmx attributes on an element like a button and wrap this in a link for progressive enhancment the link would still get triggered unless you move all the htmx attributes up to the link tag instead.

Corresponding issue:
#3356

Testing

Added regression tests for the situation

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@MichaelWest22 MichaelWest22 changed the base branch from master to dev June 27, 2025 13:25
@MichaelWest22 MichaelWest22 added the bug Something isn't working label Jun 27, 2025
@MichaelWest22 MichaelWest22 changed the title fix click events on elements wrapped by link doesn't cancel link navigation fix click events on elements wrapped by link don't cancel link navigation Jun 27, 2025
@1cg 1cg merged commit 8e489ef into bigskysoftware:dev Jun 27, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants