diff --git a/src/ui/components/Button.js b/src/ui/components/Button.js index 38901ee43..68fae2234 100644 --- a/src/ui/components/Button.js +++ b/src/ui/components/Button.js @@ -227,6 +227,7 @@ type Props = { type State = { active: boolean, + wasClosed: boolean, }; /** @@ -242,18 +243,17 @@ class Button extends React.Component< state = { active: false, + wasClosed: false, }; _ref = React.createRef(); - onMouseDown = () => this.setState({active: true}); - onMouseUp = () => this.setState({active: false}); - - onClick = (e: SyntheticMouseEvent<>) => { + onMouseDown = () => this.setState({active: true, wasClosed: false}); + onMouseUp = () => { if (this.props.disabled === true) { return; } - if (this.props.dropdown) { + if (this.props.dropdown && !this.state.wasClosed) { const menu = electron.remote.Menu.buildFromTemplate(this.props.dropdown); const position = {}; const {current} = this._ref; @@ -269,8 +269,18 @@ class Button extends React.Component< window: electron.remote.getCurrentWindow(), async: true, ...position, + callback: () => { + this.setState({wasClosed: true}); + }, }); } + this.setState({active: false, wasClosed: false}); + }; + + onClick = (e: SyntheticMouseEvent<>) => { + if (this.props.disabled === true) { + return; + } if (this.props.onClick) { this.props.onClick(e); }