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

Add methods to check if widgets are currently shown/expanded/visible or not #15573

Closed
bitcity opened this issue Jan 15, 2015 · 10 comments
Closed

Comments

@bitcity
Copy link

bitcity commented Jan 15, 2015

I'm surprised there's no request for a function that tells if a tooltip (or popover) is visible or maybe I missed it in the issues. The closest I could find was this on Stackoverflow (these are workarounds and could break unexpectedly in a future update).

How about something like:

  Tooltip.prototype.isVisible = function (obj) {
    var self = ...
    if (self && self.$tip && self.$tip.is(':visible')) {
      return true;
    } else {
      return false;
    }

I understand that it isn't completely deterministic since the result could change due to an animation timeout or mouse event.

@bitcity bitcity changed the title Find if a tooltip of popover is visible Find if a tooltip or popover is visible Jan 15, 2015
@cvrebert
Copy link
Collaborator

What's your use case?

@bitcity
Copy link
Author

bitcity commented Jan 15, 2015

I'm frequently updating the tooltip title while it's visible to the user using data-original-title (unfortunately, another undocumented property). Whether the title changes or not, I call tooltip('show'), which results in flicker. Ideally I should call it only when (i) the title needs to be updated or (ii) the tooltip has been hidden due to loss of focus. The second scenario requires checking for tooltip visibility.

@peterblazejewicz
Copy link
Contributor

for reference: quick solution:

$(selector).data('bs.tooltip') && $(selector).data('bs.tooltip').$tip.is(':visible');

@getub
Copy link

getub commented Jan 18, 2015

I find this more direct & short

$(selector).attr('aria-describedby').length != 0    

Between this and @peterblazejewicz 's solution which one's more robust and tolerant to future changes?

@Merg1255
Copy link

You should create a new report for any undocumented features you believe should be in there.

@mdo Could we have a formal way of checking visibility also for other elements? That could be consistent with the same function name on popover or tooltips.

@cvrebert
Copy link
Collaborator

It's more up to @fat since he's the JS plugin meister.
Adding a "is shown?" method to the widgets does sound reasonable to me, fwiw.
It'd probably get punted to v4 though.

@cvrebert cvrebert changed the title Find if a tooltip or popover is visible Add methods to check if widgets are currently shown/expanded/visible or not Jan 19, 2015
@bitcity
Copy link
Author

bitcity commented Jan 20, 2015

It'll be good to have an :animated selector (like this in jQuery) when we are talking about visibility.

@Merg1255
Copy link

Right. Should make it for v4. "is shown" seems nice.

@mdo
Copy link
Member

mdo commented Mar 27, 2015

Punting to v4.

@otr-tomek
Copy link

otr-tomek commented Apr 6, 2017

for bootstrap tooltips - thanks for @getub:

var $is_visible = $item.attr('aria-describedby') || false;
if (!$is_visible) {
     $item.tooltip('show');
}

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

No branches or pull requests

7 participants