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

Click events inside wrapped <label> elements do not cascade #1614

Closed
EvHaus opened this issue Nov 17, 2024 · 3 comments
Closed

Click events inside wrapped <label> elements do not cascade #1614

EvHaus opened this issue Nov 17, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@EvHaus
Copy link

EvHaus commented Nov 17, 2024

Describe the bug

The behavior of happy-dom v13.6.2 and v15.10.2 differs in that in v13 when you click on elements inside a <label> tag, it follows the browser spec and triggers the onChange events for the wrapped input element. However, in v15 this behavior is no longer working. I'm not sure where between 13.6.2 and 15.10.2 this broke.

To Reproduce

Given the following DOM structure rendered via happy-dom:

<label htmlFor="foo">
  <input id="foo" onChange={() => console.log('howdy')} type="checkbox" />
  <span id="description">Description</span>
</label>

And the following JS code

document.querySelector('#description').click();
// "howdy" should be printed

Expected behavior

If you click on the span#description element, it should trigger the onChange event on the input element. In v13.6.2 it does. In browsers it does. But in v15.10.2 it doesn't.

Screenshots
N/A

Device:
N/A

Additional context
N/A

@EvHaus EvHaus added the bug Something isn't working label Nov 17, 2024
@cythrawll
Copy link

This caught us off guard too, when random checkbox tests started to fail after happy-dom update. Looking into it the developer was using testing-librarys getByTextinstead ofgetByLabelText`. So it was selecting the div node we had in the label, so our click events were no longer triggering the output.

We had to fix the tests by using getByLabelText as a work around.

@capricorn86 capricorn86 self-assigned this Feb 24, 2025
capricorn86 added a commit that referenced this issue Feb 24, 2025
…hen clicking on an element inside of a label
capricorn86 added a commit that referenced this issue Feb 24, 2025
…hen clicking on an element inside of a label
capricorn86 added a commit that referenced this issue Feb 24, 2025
…nput inside of a label (#1743)

* fix: [#1605] Fixes issue when using filtering in TreeWalker, which caused it not to work according to spec

* fix: [#1605] Fixes issue when using filtering in TreeWalker, which caused it not to work according to spec

* chore: [#1614] Fixes issue where input change event wasnt triggered when clicking on an element inside of a label

* chore: [#1614] Fixes issue where input change event wasnt triggered when clicking on an element inside of a label
@Spixmaster
Copy link

This issue needs to be closed.

@capricorn86
Copy link
Owner

Thank you for reporting @EvHaus and @cythrawll! 🙂

This has been fixed now in v17.1.8.

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

When branches are created from issues, their pull requests are automatically linked.

4 participants