Skip to content

Commit

Permalink
Fix color picker removeEventListener
Browse files Browse the repository at this point in the history
  • Loading branch information
atrovato committed Dec 12, 2020
1 parent 86e4e7b commit 5f0ee87
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ColorDeviceType extends Component {

setColorPickerState = (open, fromEvent) => {
if (!open) {
document.removeEventListener('click', this.blur);
document.removeEventListener('click', this.blur, true);
}

this.setState({ open, fromEvent }, () => {
Expand Down Expand Up @@ -65,7 +65,6 @@ class ColorDeviceType extends Component {
componentDidMount() {
const deviceLastValue = this.props.deviceFeature.last_value;
const color = deviceLastValue === null ? undefined : `#${intToHex(deviceLastValue)}`;
console.log(deviceLastValue, color);

this.colorPicker = new iro.ColorPicker(this.colorPickerRef.current, {
width: 150,
Expand All @@ -80,6 +79,10 @@ class ColorDeviceType extends Component {
this.colorPicker.on('input:end', color => this.updateValue(color));
}

componentWillUnmount() {
document.removeEventListener('click', this.blur, true);
}

render({ device, deviceFeature }, { open }) {
const deviceLastValue = deviceFeature.last_value;
const color = deviceLastValue === null ? undefined : `#${intToHex(deviceLastValue)}`;
Expand Down

0 comments on commit 5f0ee87

Please sign in to comment.