-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
Fix: Popover with hover and click triggers closes on mouseleave #41511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
@amitrathiesh Can you remove the test file here? I think I've confirmed this fixes the issue, but we don't want that new root file to be added. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @amitrathiesh 🙏
Reviewing code changes in tooltip.js
and popover.js
is always a bit tricky. This may not be the ideal approach, but it’s the one I chose to help move things forward—it's debatable, but necessary given the limited test coverage at the moment.
My focus here isn’t on validating whether the behavior is the "correct" or intended one, but rather on ensuring there are no regressions.
To do this, I compared the Popover and Tooltip components from this branch against those in version v5.3.3.
Popover
Use case | v5.3.3 | This branch |
---|---|---|
Bootstrap documentation | 🟢 | 🟢 |
CodePen from #40802 | 🟢 | 🟢 |
trigger: 'click' |
🟢 | 🟢 |
trigger: 'hover' |
🟢 | 🟢 |
trigger: 'focus' |
🟢 | 🟢 |
trigger: 'click hover' |
🟢 | 🟢 |
trigger: 'click focus' |
🟢 | 🟢 |
trigger: 'hover focus' |
🟢 | 🟢 |
trigger: 'click hover focus' |
🟢 | 🟢 |
Tooltip
Use case | v5.3.3 | This branch |
---|---|---|
Bootstrap documentation | 🟢 | 🟢 |
trigger: 'click' |
🟢 | 🟢 |
trigger: 'hover' |
🟢 | 🟢 |
trigger: 'focus' |
🟢 | 🟢 |
trigger: 'click hover' |
🟢 | 🟢 |
trigger: 'click focus' |
🟢 | 🟢 |
trigger: 'hover focus' |
🟢 | 🟢 |
trigger: 'click hover focus' |
🟢 | 🟢 |
If anyone has additional tests in mind, please don’t hesitate to share them. 🙏
After the review, I've:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't guarantee it won't impact other things, but in my opinion, it's important that we move forward. Let's give it a try.
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 themouseleave
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:_activeTrigger[TRIGGER_CLICK]
is set totrue
._activeTrigger[TRIGGER_CLICK]
is set tofalse
.The
_leave()
method, called bymouseleave
, 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.Description
Motivation & Context
Type of changes
Checklist
npm run lint
)Live previews
Related issues
Closes #41379