I have a table with multiple rows . Each row has an onClick property which calls the class handleClick method. Each has multiple child elements. NONE of the child elements have an onClick property, and so they should not trigger the handleClick method.
Here is the code:
...
export class EventRow extends Component {
...
handleClick = (e) => {
e.preventDefault();
console.log(e.target.id);
console.log(e.target.nodeName);
}
...
render () {
return (
<tr id = { "tr" + this.props.eventdefinition.event_id } className = "noselect" onClick = { this.handleClick.bind(this) }>
<td className = "noselect">{this.props.eventdefinition.event_name}</td>
<td>
<div className = "custom-control custom-checkbox tdDiv noselect">
<input type="checkbox" className = "custom-control-input" id = { "customCheck" + this.props.eventdefinition.event_id } readOnly checked = {this.props.eventdefinition.recurring} />
<label className = "custom-control-label" htmlFor = {"customCheck" + this.props.eventdefinition.event_id}></label>
</div>
</td>
<td>
<div className = "custom-control custom-switch tdDiv noselect">
<input type="checkbox" className = "custom-control-input" id = { "customSwitch" + this.props.eventdefinition.event_id } checked = {this.props.eventdefinition.active_for_generation} onChange = { this.onChange }/>
<label className = "custom-control-label" htmlFor = {"customSwitch" + this.props.eventdefinition.event_id}></label>
</div>
</td>
</tr>
);
}
}
...
Right now you can see that in the handleClick method, there are two console.log statements. When I click on my rows, I would expect that in my console I would get an id such as tr3
and a node name TR
, but instead I get the id of whatever child was also clicked which is normally black
, and the node name of whatever child was also clicked TD
or INPUT
or LABEL
. What is going on with my event triggers?