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.

Not able to prevent click event propagation on Checkbox/TableSelectRow

See original GitHub issue

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Detailed description

Describe in detail the issue you’re having.

Discover while we implement the ‘onRowClick’ on the table rows with TableSelectRow. I don’t see a way to completely prevent the click from propagating from the Checkbox or the TableSelectRow because the event seems to be from the label https://codesandbox.io/s/sparkling-sky-2d3uj?file=/src/index.js

Is this issue related to a specific component?

Checkbox TableSelectRow

What did you expect to happen? What happened instead? What would you like to see changed?

Checkbox.onClick or TableSelectRow.onSelect should prevent the click from bubbleing up.

What browser are you working in?

Chrome

What version of the Carbon Design System are you using?

Latest

What offering/product do you work on? Any pressing ship or release dates we should be aware of?

CP4D - WKC

Steps to reproduce the issue

  1. Step one
  2. Step two
  3. Step three
  4. etc.

Please create a reduced test case in CodeSandbox

https://codesandbox.io/s/sparkling-sky-2d3uj?file=/src/index.js

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
tay1orjonescommented, Nov 19, 2021

@nelsonchen90 that codesandbox was super helpful, thanks! I see what you’re saying - the click event associated with the input can be caught through onSelect, but the click event associated with the label can’t be caught through onSelect. This is because the event is placed directly on the input and not on a wrapper of the input and label.

I’m sure there’s some way we can address this. From my understanding, the label for InlineCheckbox never renders visible text or a visible click target. I can’t think of a reason why a consumer would need access to the click event specifically from the label. What might make the most sense here is to immediately call stopPropogation on the label click event internal to InlineCheckbox.

1reaction
nelsonchen90commented, Nov 19, 2021

Sorry for the late response!

@tay1orjones the problem with InlineCheckbox and capture the click event is that there are 2 items being clicked in it

  • input
  • label

Although we can stop the click event from propagating by using TableSelectRow.onSelect there is still another event being ‘escaped’/propagated from the label.

I have created a super reduced case https://codesandbox.io/s/dark-fog-ubul2?file=/src/index.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent a checkbox within a table using an onclick ...
Clicking on a row should cause an event but selecting a checkbox should not. I found a lot of answers to this but...
Read more >
event.stopPropagation() in a modular system
It seems desirable that widgets should not be allowed to interfere with event propagation during capturing or bubbling. If we were to remove...
Read more >
Event.stopPropagation() - Web APIs | MDN
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Read more >
The Dangers of Stopping Event Propagation
In case it's not clear what this code is doing, here's a quick rundown: If a click event propagates to the <html> element,...
Read more >
event.stopImmediatePropagation()
To simply prevent the event from bubbling to ancestor elements but allow other event handlers to ... it is not possible to stop...
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