From 95ddec7b20e55ecb2fd7336f4e049da5ed8716e1 Mon Sep 17 00:00:00 2001
From: "google-labs-jules[bot]"
<161369871+google-labs-jules[bot]@users.noreply.github.com>
Date: Sun, 1 Jun 2025 18:23:02 +0000
Subject: [PATCH 1/4] Fix: Popover with hover and click triggers closes on
mouseleave
When a popover is configured with `trigger: 'hover click'`,
if you open it by a click, it would incorrectly close when the
mouse pointer leaves the trigger element. This was because the
`mouseleave` event (part of the hover trigger) would hide the
popover without adequately respecting the click trigger's intent
to keep it open.
This commit modifies the click event listener within `Tooltip.js`
(which Popover extends) to explicitly manage the `_activeTrigger[TRIGGER_CLICK]`
state:
- When a click opens the popover or makes a hover-opened popover
sticky, `_activeTrigger[TRIGGER_CLICK]` is set to `true`.
- When a click closes an already click-activated popover,
`_activeTrigger[TRIGGER_CLICK]` is set to `false`.
The `_leave()` method, called by `mouseleave`, already checks
`_isWithActiveTrigger()`. With `_activeTrigger[TRIGGER_CLICK]`
now accurately reflecting the click state, `_leave()` will not
hide a click-activated popover when the mouse leaves the trigger
element. The popover will now correctly remain open until a
subsequent click closes it.
---
js/src/tooltip.js | 5 +
test-popover.html | 1012 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 1017 insertions(+)
create mode 100644 test-popover.html
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index 097477f7a1a8..898558fadc88 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -448,6 +448,11 @@ class Tooltip extends BaseComponent {
if (trigger === 'click') {
EventHandler.on(this._element, this.constructor.eventName(EVENT_CLICK), this._config.selector, event => {
const context = this._initializeOnDelegatedTarget(event)
+ if (context._isShown() && context._activeTrigger[TRIGGER_CLICK]) {
+ context._activeTrigger[TRIGGER_CLICK] = false
+ } else {
+ context._activeTrigger[TRIGGER_CLICK] = true
+ }
context.toggle()
})
} else if (trigger !== TRIGGER_MANUAL) {
diff --git a/test-popover.html b/test-popover.html
new file mode 100644
index 000000000000..fc9cb335340e
--- /dev/null
+++ b/test-popover.html
@@ -0,0 +1,1012 @@
+
+
+