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

Open
EvHaus opened this issue Nov 17, 2024 · 1 comment
Open

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

EvHaus opened this issue Nov 17, 2024 · 1 comment
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.

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