August Haug Hem August Haug Hem - 2 months ago 13
CSS Question

css isolate child pointer event

I want to be able to separate the pointer event on the checkbox, making it not trigger the parent pointer event which opens a modal.

Here is a gif showing my issue:

To elaborate on what is going on here, the table rows are clickable and will open up a modal that will show extended information regarding the the clicked row.
In addition to this I have a checkbox on this row which has a click event itself and I want to isolate this checkbox from triggering the "row" click event.


You need to use e.stopPropagation() in the handleClick function for the checkbox. This will prevent the click event from checkbox bubbling up to the parent row element.

class App extends React.Component {
  handleCheckClick = (e) => {
     console.log('checkbox clicked');
   handleRowClick = (e) => {
     console.log('row clicked');
  render() {
   return ( <table>
        <th>First Name</th>
        <th>Last Name</th>
        <tr onClick={this.handleRowClick}>
            <input type="checkbox" onClick={this.handleCheckClick}/>


ReactDOM.render(<App/>, document.getElementById('app'));
<script src=""></script>
<script src=""></script>
<div id="app"></div>