From 14f26af060ec176e7fe463d458acccd850aa3327 Mon Sep 17 00:00:00 2001 From: Sjaak Luthart Date: Fri, 23 Jun 2017 08:51:43 +0200 Subject: [PATCH 1/3] Added check for open state. --- src/commands/index.jsx | 11 +++++++---- src/icon-menu/index.jsx | 8 +++++++- src/select/index.jsx | 8 +++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/commands/index.jsx b/src/commands/index.jsx index b0cb4d00..16147e87 100644 --- a/src/commands/index.jsx +++ b/src/commands/index.jsx @@ -113,11 +113,14 @@ class Commands extends Component { handleClickOutside = () => { const { commands } = this.props; + const { open } = this.state; - this.setState({ - open: false, - commands - }); + if (open) { + this.setState({ + open: false, + commands + }); + } } handleSelect = (event, command) => { diff --git a/src/icon-menu/index.jsx b/src/icon-menu/index.jsx index f2a0b76a..1edb2cc0 100644 --- a/src/icon-menu/index.jsx +++ b/src/icon-menu/index.jsx @@ -92,7 +92,13 @@ class IconMenu extends Component { onMenuClose(); } - handleClickOutside = () => this.closeMenu() + handleClickOutside = () => { + const { open } = this.state; + + if (open) { + this.closeMenu(); + } + } applyCloseMenuToChildren(children) { return React.Children.map( diff --git a/src/select/index.jsx b/src/select/index.jsx index 5dcc30d5..dc1831eb 100644 --- a/src/select/index.jsx +++ b/src/select/index.jsx @@ -110,7 +110,13 @@ class Select extends Component { }); } - handleClickOutside = () => this.closeSelect() + handleClickOutside = () => { + const { open } = this.state; + + if (open) { + this.closeSelect(); + } + } handleKeyUp = (event) => { if (event.which === 27) { From d77ba18e84d3e030d13fe6449c3011142a26ddab Mon Sep 17 00:00:00 2001 From: Sjaak Luthart Date: Fri, 23 Jun 2017 09:01:51 +0200 Subject: [PATCH 2/3] Moved checks to close functions instead. --- src/icon-menu/index.jsx | 15 +++++++-------- src/select/index.jsx | 16 ++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/icon-menu/index.jsx b/src/icon-menu/index.jsx index 1edb2cc0..aaab0b58 100644 --- a/src/icon-menu/index.jsx +++ b/src/icon-menu/index.jsx @@ -83,22 +83,21 @@ class IconMenu extends Component { closeMenu() { const { onMenuClose } = this.props; + const { open } = this.state; + + if (!open) { + return false; + } this.setState({ open: false, positioned: false }); - onMenuClose(); + return onMenuClose(); } - handleClickOutside = () => { - const { open } = this.state; - - if (open) { - this.closeMenu(); - } - } + handleClickOutside = () => this.closeMenu() applyCloseMenuToChildren(children) { return React.Children.map( diff --git a/src/select/index.jsx b/src/select/index.jsx index dc1831eb..8ddbbae1 100644 --- a/src/select/index.jsx +++ b/src/select/index.jsx @@ -104,19 +104,19 @@ class Select extends Component { } closeSelect() { - this.setState({ + const { open } = this.state; + + if (!open) { + return false; + } + + return this.setState({ open: false, positioned: false }); } - handleClickOutside = () => { - const { open } = this.state; - - if (open) { - this.closeSelect(); - } - } + handleClickOutside = () => this.closeSelect() handleKeyUp = (event) => { if (event.which === 27) { From 5b0f50c21b9eecf66f5168000ba776ac7c1c8518 Mon Sep 17 00:00:00 2001 From: Sjaak Luthart Date: Fri, 23 Jun 2017 09:05:17 +0200 Subject: [PATCH 3/3] Changed check. --- src/commands/index.jsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/commands/index.jsx b/src/commands/index.jsx index 16147e87..f1080361 100644 --- a/src/commands/index.jsx +++ b/src/commands/index.jsx @@ -115,12 +115,14 @@ class Commands extends Component { const { commands } = this.props; const { open } = this.state; - if (open) { - this.setState({ - open: false, - commands - }); + if (!open) { + return false; } + + return this.setState({ + open: false, + commands + }); } handleSelect = (event, command) => {