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

[bug]: Checkbox in a form with onClick on parent causes infinite state update #3192

Open
Spoof14 opened this issue Oct 24, 2024 · 2 comments

Comments

@Spoof14
Copy link

Spoof14 commented Oct 24, 2024

Bug report

Current Behavior

With the simple example of

function App() {
  const [isChecked, setIsChecked] = useState(false);

  return (
      <form>
        <div onClick={() => setIsChecked((prev) => !prev)}>
          <Checkbox checked={isChecked} />
          <span>test</span>
        </div>
      </form>
  )
}

The app crashed due to infinite state updates. Stopping propogation does nothing.

Expected behavior

The checkbox goes from unchecked to checked

Reproducible example

CodeSandbox Template

Suggested solution

Stop firing onClick multiple times. Perhaps make the checkbox into an actual <input type='checkbox'>

Your environment

Software Name(s) Version
Radix Package(s) checkbox 1.1.2
React n/a 18.3
Browser chrome 130
Assistive tech
Node n/a
npm/yarn
Operating System windows 11
@Spoof14
Copy link
Author

Spoof14 commented Oct 24, 2024

Relates to ##2549 (comment)

@Spoof14 Spoof14 changed the title Checkbox in a form with onClick on parent causes infinite state update [bug]: Checkbox in a form with onClick on parent causes infinite state update Oct 24, 2024
@CarlosVergikosk
Copy link

Same here, really annoying

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