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

Checkbox "checked" updated triggers onClick event on parent div when inside a form #3265

Open
Tom-Aive opened this issue Dec 3, 2024 · 2 comments

Comments

@Tom-Aive
Copy link

Tom-Aive commented Dec 3, 2024

Bug report

Current Behavior

When a checkbox is inside a <form>, any update on its checked prop will trigger an onClick event that will propagate to its parent.

Bug found while making a form with a select all checkbox that would mark all the other checkboxes as checked.
The other checkboxes were located inside <div> that were clickable.

The onClick event originates from the internal <input> used by the checkbox.

Expected behavior

The event on the internal <input> should not propagate to the parent.
It also shouldn't be triggered after an update on the checked prop.

Reproducible example

CodeSandbox example

Suggested solution

See Expected behavior.

Additional context

Might be the same issue as #3192 and #2704.

Your environment

Software Name(s) Version
Radix Package(s) checkbox 1.1.2
React n/a 17.0.1
Browser
Assistive tech
Node n/a
npm/yarn
Operating System
@paullfhc
Copy link

paullfhc commented Dec 6, 2024

Hi, on my side, I avoid this issue by removing the onClick from the div, like this :

<form>
      <div>
        <Checkbox.Root checked={isChecked} onCheckedChange={setIsChecked}> 
          [ <Checkbox.Indicator></Checkbox.Indicator> ]
        </Checkbox.Root>
        <span>test</span>
      </div>
</form>

@Tom-Aive
Copy link
Author

Tom-Aive commented Dec 6, 2024

In my case I can't because I need the whole div to be clickable (it contains other elements than the checkbox).

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

No branches or pull requests

2 participants