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

Input type checkbox indeterminate state not working #1439

Open
MarvinKubus opened this issue May 15, 2024 · 4 comments
Open

Input type checkbox indeterminate state not working #1439

MarvinKubus opened this issue May 15, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@MarvinKubus
Copy link

Describe the bug
A checkbox with the indeterminate state being true should go to false when clicked, but this is not happening with happy-dom, it does with jsdom.

To Reproduce
Minimal example: https://stackblitz.com/edit/vitest-dev-vitest-rzc6un?file=test%2Fbasic.test.ts
Switch the happy-dom to jsdom there to see the test succeed.

Expected behavior
When clicking a checkbox element, I expect the indeterminate state to switch to false.

@MarvinKubus MarvinKubus added the bug Something isn't working label May 15, 2024
@malko
Copy link
Contributor

malko commented Jun 27, 2024

This is the JSDOM behavior but not the default behavior. You can try to make a minimal file example like this one:

<!DOCTYPE html>
<html><body>
  <input type="checkbox" />
  <script type="text/javascript">
    document.querySelector('input').indeterminate = true
  </script>
</body></html>

And test it with chrome or firefox, with chrome it constantly make it true when clicked, and with firefox reloading the page will make it false or true changing the value on each reload.
The indeterminate state can only be set by javascript and is purely visual. It is the checked state that should determinate the new state when clicked not the indeterminate state at all.

So if your input is checked and indeterminate it should when clicked be unchecked,
if it was unchecked and indeterminate it should be checked when clicked.

@malko
Copy link
Contributor

malko commented Jun 27, 2024

There's still a problem with the happy-dom implementation, as triggering a click event on the element will not change the indeterminate state at all, but is should be passed to false.

@malko
Copy link
Contributor

malko commented Jun 27, 2024

Also I can see the actual implementation sets an attribute indeterminate on the input element but it should not as indeterminate is not meant to be an input attribute.

@malko
Copy link
Contributor

malko commented Jun 27, 2024

will propose a PR about this in few days

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