From 66a9a09236ec2686fd8af6b76089140b9f79b66f Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Fri, 28 Jun 2024 15:10:23 -0700 Subject: [PATCH] Keep popover alive when mouse enters the user card (#154) --- scripts/ui.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/ui.js b/scripts/ui.js index 6062634..11def27 100644 --- a/scripts/ui.js +++ b/scripts/ui.js @@ -411,17 +411,33 @@ UserProfileCard.prototype.updateTarget = function(target) { UserProfileCard.prototype.setLeaveEvent = function() { let validTargets = [this.el, this.target]; + // The UI lives directly under document so switching to the UI will trigger + // the leave event. We need to dispatch the event to the popover to prevent + // the popover from disappearing. + const dispatchToPopover = (event) => { + let node = this.target; + while (node && node != document) { + if (node.classList && node.classList.contains("v-popover")) { + node.dispatchEvent(new Event(event)); + break; + } + node = node.parentNode; + } + } + this.leaveCallback = () => { if (this.disable()) { for (let target of validTargets) { target.removeEventListener("mouseleave", this.disableDebounce); target.removeEventListener("mouseenter", this.enterCallback); } + dispatchToPopover("mouseleave"); } } this.enterCallback = () => { clearTimeout(this.disableDebounce.timer); + dispatchToPopover("mouseenter"); this.cursorInside = true; }