checkbox icon indicating copy to clipboard operation
checkbox copied to clipboard

expose `currentTarget` in `handleChange`

Open goldylucks opened this issue 7 years ago • 0 comments

Happy to send a PR :)

From react/flow docs:

Note: To get the element instance, like HTMLButtonElement in the example above, it is a common mistake to use event.target instead of event.currentTarget. The reason why you want to use event.currentTarget is that event.target may be the wrong element due to event propagation.

Relevant code:

  handleChange = (e) => {
    const { props } = this;
    if (props.disabled) {
      return;
    }
    if (!('checked' in props)) {
      this.setState({
        checked: e.target.checked,
      });
    }
    props.onChange({
+     currentTarget: e.currentTarget,
      target: {
        ...props,
        checked: e.target.checked,
      },
      stopPropagation() {
        e.stopPropagation();
      },
      preventDefault() {
        e.preventDefault();
      },
      nativeEvent: e.nativeEvent,
    });
  };

goldylucks avatar Aug 07 '18 20:08 goldylucks