I'm using Bootstrap to build a basic table and I want to handle the user clicking on a row so that I can mark it as selected.
My list items have nested elements. When I click directly on the list item the onClick handler gets called and 'event.target.value' is set correctly.
When I click on a nested element then the onClick handler still gets called but the 'event.target.value' is undefined.
I've read lots of suggestions based on binding inside the render method but I know this is not a recommended thing to do.
class TeamListItem extends Component {
constructor(props) {
super(props);
this.internalHandleSelectTeam = this.internalHandleSelectTeam.bind(this);
}
internalHandleSelectTeam(event) {
console.log(event.target.value);
}
render() {
const team = this.props.team;
return (
<li className="list-group-item" value={team.teamId} onClick={this.internalHandleSelectTeam}>
<Row>
<Col xs={10} sm={8} md={6}>
{team.teamName}
</Col>
<Col xs={2} sm={4} md={6}>
{team.resourceList.length}
</Col>
</Row>
</li>
);
}
}
export { TeamListItem }