Skip to content
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 hover-popover/tooltip flickering when mouse re-enters #14273

Merged
merged 1 commit into from
Sep 7, 2014

Conversation

sgonyea
Copy link
Contributor

@sgonyea sgonyea commented Jul 29, 2014

I'm not exactly happy with the code change I've made to fix this issue, but this at least demonstrates a fix (as well as the bug itself).

JSBin: http://jsbin.com/hajeta/2/

Issues:

  • Mouse out / mouse in over elements within the popover, the popover will continually flicker (until your mouse hovers over only the popover itself. no child elements)
  • Mouse out / mouse in, if the user scrolled within the popover -- that scorll position is lost (b/c the popover is recreated repeatedly)

Steps to trigger the flickering bug:

  • Hover over the text "Hover here!"
  • Mouse over the tooltip itself
  • Mouse-out and then quickly mouse back in (specifically, mouse back in over the text itself)
  • See a flicker. Then mouse up over other text. The flickering continues.

Additionally: You can scroll within the popover and see the flicker / (continual) resetting of the inner scrollbar position.

Hopefully the explanation and the demo make sense.

Thank you very much! Bootstrap is fantastic.

@cvrebert cvrebert added the js label Jul 29, 2014
@cvrebert cvrebert added this to the v3.2.1 milestone Jul 29, 2014
@hnrch02
Copy link
Collaborator

hnrch02 commented Jul 29, 2014

Here's a Bin with your changes: http://jsbin.com/lopupi/1

@sgonyea
Copy link
Contributor Author

sgonyea commented Jul 29, 2014

Thank you for creating that, @hnrch02!

@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 1, 2014

@cvrebert I hate to be a bother, but is there any chance I might get some quick input on this PR? My mind is still pretty fresh, on the topic, so I'd love to get it into acceptable shape if possible.

Thank you!

@cvrebert
Copy link
Collaborator

cvrebert commented Aug 1, 2014

I'm not really qualified to review this in-depth. You'll have to wait for @fat to get around to reviewing this.

@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 4, 2014

Gotcha! Thanks for taking a quick look, @cvrebert. I may be able to dig this fix in a little deeper near the triggering of the event (though that wasn't clear when I first tried). I'll take another quick stab to see if I can offer something cleaner for @fat to review.

@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 4, 2014

I was originally triaging this bug in Bootstrap 3.1, and had with this simpler/better fix that now works. I'm going to force-push this much simpler commit in.

@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 4, 2014

Done. Now it's one-liner with fewer code paths. I don't see any visual glitches that are specific to this change.

@cvrebert
Copy link
Collaborator

cvrebert commented Aug 4, 2014

It would be great if you could add either a visual test or unit test for this.

@@ -103,6 +103,8 @@
var self = obj instanceof this.constructor ?
obj : $(obj.currentTarget).data('bs.' + this.type)

if (self && self.hoverState === 'in') return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be

if (self && self.hoverState == 'in') return

@cvrebert
Copy link
Collaborator

cvrebert commented Aug 4, 2014

(Filed Medium/phantomjs#209 regarding the unrelated Travis failure.)

@@ -151,6 +153,8 @@

var $tip = this.tip()

if ($tip.is(':visible')) return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semicolon.

@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 4, 2014

Thanks, @cvrebert.

Also, I had to add one more commit. It seems like there still needs to be a check for whether or not the tooltip is still visible.

I'm wondering if there's a case where this can cause issues when manually triggering the tooltip... If you have a delay AND you quickly hide + show the tooltip.

So I think I need to limit my code changes to the enter/leave methods.

@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 4, 2014

And now I've got what I think is a final PR. I just realized that hoverState IS being set to null, so I can rely on the in/out states == "still/gonna be visible".

@cvrebert
Copy link
Collaborator

cvrebert commented Aug 4, 2014

So, why isn't the check != null then?

@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 4, 2014

It probably should be. I'll fix.

@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 4, 2014

Here's a JS bin with the current set of code changes:

http://jsbin.com/tumar/1

I'll work on adding a unit test -- are the visual tests just a manual spot-check? I wasn't sure if my addition would make it too noisy.

Thanks again!

@cvrebert
Copy link
Collaborator

cvrebert commented Aug 4, 2014

@sgonyea Yeah, the visual tests are completely manual. (Which is why unit tests are preferred when possible.)

@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 6, 2014

That was fun. The tests helped reveal that I needed to go back to my original commit, and just rely on this.$tip.is(':visible').

@cvrebert -- I've added some pretty ugly tests and decided to get some feedback. They involve a lot of teeth pulling, so I'll work on cleaning it up soon.

@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 6, 2014

Oh right, and a JSBin with the current code: http://jsbin.com/tumar/2

test('should not reload the tooltip on subsequent mouseenter events', function () {
var contentData = []
var titleHtml = function (skipSave) {
var uid = $.fn.bootstrapTooltip.Constructor.prototype.getUID('tooltip').toString()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the toString here.

@fat
Copy link
Member

fat commented Aug 27, 2014

everything @hnrch02 said 👍

- is(':visible') seems to be the only reliable check, without a refactoring of how hoverState is used
- tests need improvement
@sgonyea
Copy link
Contributor Author

sgonyea commented Aug 29, 2014

Done. Thanks a lot for the review, @hnrch02! I've made the assertion inside the tooltip a little less strict.

@cvrebert
Copy link
Collaborator

@fat So, is this now good to go?

fat added a commit that referenced this pull request Sep 7, 2014
Fix hover-popover/tooltip flickering when mouse re-enters
@fat fat merged commit c22b270 into twbs:master Sep 7, 2014
@fat
Copy link
Member

fat commented Sep 7, 2014

yep, thanks!

@cvrebert cvrebert mentioned this pull request Sep 7, 2014
@creative3d
Copy link

Hello everybody. I've found this issue looking for a fix for this joomla issue: joomla/joomla-cms#10821 . If it's not much of a trouble, please help to fix that issue, or just write some advice to joomla developers because they are not trying to fix it, they are just waiting for you. Or maybe you can provide with a hot fix or something... Thanks.

@C-Lodder
Copy link
Contributor

@creative3d - In Joomla we're still using BS2 which is no longer officially supported. To get the issue fixed, we'll either need to do it ourselves or perhaps it has already been fixed by a 3rd party who decided to keep supporting BS2

@creative3d
Copy link

@C-Lodder, "it has already been fixed" well, it wasn't, as far as I know, I was just able to pay their attention on this from the third attempt two month ago, no movements since then. As for fixing ourselves, I'd like to, but I'm not a developer, have no idea how. Thanks for answering.

@C-Lodder
Copy link
Contributor

I'll look into it: joomla/joomla-cms#10821 (comment)

@creative3d
Copy link

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants