From 8fd5d24a9ff47030214b8182e001fe784a986503 Mon Sep 17 00:00:00 2001 From: Lydie Danet Date: Tue, 19 Jun 2018 18:35:53 +1200 Subject: [PATCH 1/2] Set hover state to false when touching outside --- .../react-accessible-tooltip/src/Tooltip.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/react-accessible-tooltip/src/Tooltip.js b/packages/react-accessible-tooltip/src/Tooltip.js index 2b2065a..18b770f 100644 --- a/packages/react-accessible-tooltip/src/Tooltip.js +++ b/packages/react-accessible-tooltip/src/Tooltip.js @@ -91,11 +91,20 @@ class Tooltip extends Component { activeElement instanceof Element && target instanceof Element && this.container instanceof Element && - !this.container.contains(target) && // touch target not a tooltip descendent - this.state.isFocused // prevent redundant state change + !this.container.contains(target) // touch target not a tooltip descendent ) { - this.setState({ isFocused: false }); - activeElement.blur(); + // prevent redundant state change + if (this.state.isFocused) { + this.setState({ isFocused: false }); + } + if (this.state.isHovered) { + // prevent redundant state change + this.setState({ isHovered: false }); + } + // don't blur active element if outside + if (this.container.contains(activeElement)) { + activeElement.blur(); + } } else if ( activeElement instanceof Element && target instanceof Element && From c0e677e73df14ff76a9ac072b63339cdc806aaed Mon Sep 17 00:00:00 2001 From: Lydie Danet Date: Tue, 19 Jun 2018 18:42:17 +1200 Subject: [PATCH 2/2] Make comment consistent --- packages/react-accessible-tooltip/src/Tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-accessible-tooltip/src/Tooltip.js b/packages/react-accessible-tooltip/src/Tooltip.js index 18b770f..f2a70d0 100644 --- a/packages/react-accessible-tooltip/src/Tooltip.js +++ b/packages/react-accessible-tooltip/src/Tooltip.js @@ -97,8 +97,8 @@ class Tooltip extends Component { if (this.state.isFocused) { this.setState({ isFocused: false }); } + // prevent redundant state change if (this.state.isHovered) { - // prevent redundant state change this.setState({ isHovered: false }); } // don't blur active element if outside