question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Checkbox: onClick fires parent onClick twice

See original GitHub issue

Bug Report

I just upgraded to v0.85 (from 0.82.5) seeing this release is supposed to fix this issue, https://github.com/Semantic-Org/Semantic-UI-React/pull/3351. My issue might be slightly different though.

I have the following subset of code:

         <li
            onClick={this.liClickHandler}
          >
            <div className="border--left" />
            <div className="infoIconContainer">
              <Popup trigger={<Icon name="info circle" />} content={node.data.tooltipText} inverted />
            </div>
            <div className="checkboxContainer">
              <Checkbox
                id={node.id}
                checked={node.data.active}
                indeterminate={node.data.indeterminate}
                radio={treeType === 'Radio'}
                onClick={e => e.stopPropagation()}
              />...

When the user clicks the checkbox, which is a radio button, it runs the li’s onClick event twice. If the user clicks the li it runs once.

It appears to only do this when I specify the id property. This can be validated in the test case below

Steps

Use the checkbox with an ID specified and a parent click event and note it fires twice. It fires twice for radio and checkboxes.

Put onclick on the checkbox and it only fires once.

Expected Result

it fires once

Actual Result

it fires twice. In debugging the this.liClickHandler, I notice that the event object is slightly different the 2nd time it calls.

First time, event.target is label, the second time it’s the input. Appears both controls are pushing the click.

Version

"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.85.0",

Testcase

https://codesandbox.io/s/88zzv64rn8

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Fabianopbcommented, Feb 13, 2019

I’ve worked on the referred issue #3351 I think I know where the problem could come from, will submit a PR soon!

0reactions
layershiftercommented, Feb 26, 2019

Need a 🍻?

We need @levithomason because only he has release rights 😸

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clicking on an input[checkbox]'s label will fire twice the ...
The problem is, clicking on the <label> will trigger the parent's click twice, whereas clicking on the <input> will trigger it only once....
Read more >
checkbox inside label fires twice - JSFiddle - Code Playground
1. <p id="explanation">Click <strong>checkbox</strong> to fire onclick only once.<br /> ; 2. Click <strong>label-text</strong> to fire onclick twice.</p> ; 3. ​.
Read more >
Event Bubbling and Event Catching in JavaScript and React
She has a single parent div with an onClick event handler that, when clicked, calls everyone to the table to eat her food....
Read more >
ASP.NET Core Blazor event handling - Microsoft Learn
Since propagated click events normally fire the OnSelectParentDiv method, selecting the second child <div> results in the parent <div> message ...
Read more >
Event.preventDefault() - Web APIs | MDN
addEventListener("click", checkboxClick, false); function checkboxClick(event) { let warn = "preventDefault() won't let you check this!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found