-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
fix tooltips disappearing after trying to interact during their fade out animation #33289
Conversation
This fixes the issue, but doesn't fix the issue with the tooltip randomly showing up in the wrong position :/ 2021-03-06_20-07-58.mp4It probably is a separate issue, though. But yeah, feel free to do what you think it's best with mocking since we have been already bitten by this issue. |
Yeah - I figured I'd leave that to #31646 as the positioning issues seem to have everything to do with mouseout and mouseover behavior being investigated there already. You can actually very consistently get the position of the tooltip to mess up if you slowly move your mouse onto the button from where the tooltip is going to appear... because it triggers the following events
Screen.Recording.2021-03-06.at.1.20.37.PM.movWhich is of course why adding Long story short, that seemed separate from the already being dealt with #31646 so I've ignored it for this. It does though seem that the code included in this pr makes solving the other issue less complicated. I'll leave this pr as is, lmk if you'd like anything changed here or a hand on the other issue |
If you can help us with the other issue, please go ahead :) Lack of tests caused these issues in the first place. Currently the tooltip and event handling issues are blocking us. |
This should now resolve #31646 as well. My initial thinking was a bit off. The issue with tooltips ending up in weird locations was due to trying to create a NEW tooltip before the other one was destroyed. I also decided NOT to handle tooltip/trigger overlapping, because since it looks like tooltip offset is allowed to be customized by users easily, in the edge cases that it matters users can just make the offset larger. Lastly, I changed the default ordering of |
Thanks for the PR @RyanBerliner Change in the That default pattern may not be preferred by everyone but that can be overridden by the configuration of the tooltip. Ref: #32843 and https://popper.js.org/docs/v2/modifiers/flip/#fallbackplacements |
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.
Can you please add tests for the second issue as well 🙂
|
@RyanBerliner I haven't looked at your changes yet, but I wanted to say a huge thank you for jumping into these issues! ❤️ The tooltip and event issues are the ones blocking as AFAICT, so this would unblock beta3 and generally v5. |
js/src/tooltip.js
Outdated
@@ -283,7 +283,11 @@ class Tooltip extends BaseComponent { | |||
|
|||
EventHandler.trigger(this._element, this.constructor.Event.INSERTED) |
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.
Also, please consider this INSERTED
event. Depending on how you anticipate this event to be used by people, it may make most sense to only trigger it on true, new popper creation, otherwise it will be triggered every time someone re-enters a tooltip trigger while its transitioning to hidden.
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.
True, it should be triggered only when the tooltip is inserted in the DOM.
Line 280 in 548be2e
if (!this._element.ownerDocument.documentElement.contains(this.tip)) { |
@rohit2sharma95 @GeoSot LGTY? I think it's a clean way to fix the issues we are hitting. |
Maybe I am wrong and maybe it not the proper place to ask for this, but I think context._activeTrigger.click = !context._activeTrigger.click Wouldn't be easier to keep only |
While I think this could be refactored to be a boolean it also keeps track if something is focused while not being hovered for example. |
@RyanBerliner added a draft PR #33310 that would address what you mentioned earlier (some little revenge for you being faster with this one 😁) |
expect(tooltip.getTipElement().getAttribute('data-popper-placement')).toBe('top') | ||
done() | ||
}, 200) | ||
}, 0) |
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.
@RyanBerliner can you leave a comment on top of first time-out explaining its purpose with zero delay? Or replace zero timeout with 1milisec
I suppose you wrote it like this to give a minimum time to Tooltip to be rendered
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.
tbh, I know it's not a good reason, but I did it this way because it matches styling from this existing tooltip test. And given that the following is true:
setTimout(() => console.log('here 1'), 0)
console.log('here 2')
------ Outputs ------
"here 2"
"here 1"
I figured that it's the preferred syntax in this case. I can change it, but if I do it should probably be changed in the other tests as well for consistency?
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.
Good point.
Personally I would prefer at least the zero to be 1 but I think,cc/ @XhmikosR the monster of code consistency, will give us his opinion
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.
Would be nice to streamline these but in a separate PR after this. For now, I just want us to merge this and any other beta3 PRs so that we release beta3 next week :)
2eadd90
to
0bd32a3
Compare
Thanks @RyanBerliner! If you have time, feel free to help us with any other JS-related PRs :) |
Resolves #32372, resolves #31646
This points out that components that transition may have a blind spot in testing. Since transition duration & delay is computed using getTransitionDurationFromElement(element), which gets transitions from css, its always going to be returning 0 in the unit tests unless otherwise mocked or styled inline. That means that any components that use this transition method will have tests that mostly ignore them... which may not actually matter (likely true), but at least in this case it does matter.
Ideal in testing you'd mock the actual
getTransitionDurationFromElement(element)
imo, and just return the duration, however I was having some trouble getting jasmine spys to properly do this. I went for the next best thing in this case, which is mocking computed styles to get a non-zero return from that function. Happy to change it if anyones got ideas.Preview: https://deploy-preview-33289--twbs-bootstrap.netlify.app/docs/5.0/components/tooltips/