From 8cae93d4c8f1db9b3eef205f64bf93659e34da9e Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 21 Dec 2021 17:03:24 -0600 Subject: [PATCH] Fix tooltip not closing when focus lost The assumption that "a click handler somewhere else will close the popover if necessary" does not appear to be valid. If the user clicks on a non-focusable element. There are no other events that cause the popover to close other than mouseleave, but the mouse is not over the target when focus is lost. Fixes #4503. --- packages/popover2/src/popover2.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/popover2/src/popover2.tsx b/packages/popover2/src/popover2.tsx index cf1e5f27ed..7cfa660a97 100644 --- a/packages/popover2/src/popover2.tsx +++ b/packages/popover2/src/popover2.tsx @@ -536,10 +536,6 @@ export class Popover2 extends AbstractPureComponent2, IPopov private handleTargetBlur = (e: React.FocusEvent) => { if (this.props.openOnTargetFocus && this.isHoverInteractionKind()) { - // e.relatedTarget ought to tell us the next element to receive focus, but if the user just - // clicked on an element which is not focusable (either by default or with a tabIndex attribute), - // it won't be set. So, we filter those out here and assume that a click handler somewhere else will - // close the popover if necessary. if (e.relatedTarget != null) { // if the next element to receive focus is within the popover, we'll want to leave the // popover open. @@ -549,6 +545,8 @@ export class Popover2 extends AbstractPureComponent2, IPopov ) { this.handleMouseLeave((e as unknown) as React.MouseEvent); } + } else { + this.handleMouseLeave((e as unknown) as React.MouseEvent); } } this.lostFocusOnSamePage = e.relatedTarget != null;