score:3

Accepted answer

You can wrap the Checkbox with a regular label to make the label toggle the checkbox.

<label> Label <Checkbox/></label>;

You can also control the Checkbox by using a piece of state for the checked prop and toggle that programmatically.

const { Checkbox } = window['material-ui'];

class App extends React.Component {
  state = { isChecked: false };

  toggle = () => {
    this.setState(prevState => ({ isChecked: !prevState.isChecked }));
  };

  render() {
    return (
      <div>
        <Checkbox checked={this.state.isChecked} onChange={this.toggle} />
        <button onClick={this.toggle}>Toggle</button>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("root"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@material-ui/core/umd/material-ui.production.min.js"></script>

<div id="root"></div>


Related Query

More Query from same tag