Tippyjs: data-tippy-trigger not overriding default values

Created on 6 Sep 2019  路  5Comments  路  Source: atomiks/tippyjs

Bug description

I am initializing tippy.js with

var tippyOptions = {
  target: '.tippy'
};

tippy('body', tippyOptions);

For some cases I want the tooltip to only show on click (and hot on mouseneter, focus), so I use data-tippy-trigger="click"

<button class="tippy" data-tippy-trigger="click" data-tippy-content="content">tooltip trigger</button>

The problem is that the tooltip is still showing on mouseenter the first time, after that it shows only on click. Is there a way to not trigger it on mouseenter also on the first time?

Reproduction

You can find an example to reproduce here: https://jsbin.com/jupixaqoqo/2/edit?html,css,js,output

馃悰 bug

Most helpful comment

+1 for this. I was surprised when this didn't work out of the box. I was expecting it to be a common need. I.e., I want 90% of popovers to be triggered with a click - but putting 'data-tippy-trigger' on an element to override it. I thought that would be the default behavior.

All 5 comments

For this to work, we'd probably need to listen all the events simultaneously and add a check for the target element to ensure its trigger matches the bubbling event, since the delegate instance only uses its own trigger option and doesn't "know" about potential target elements' attributes triggers

@atomiks Thanks for the very fast response.

My guess is I could use a MutationObserver and use tippy('.tippy'); for all newly created elements with the class .tippy - would this work as a workaround for now and do you maybe have a hint how this could be achieved?

I would create two separate delegate instances and use a different class for the "click" targets.

+1 for this. I was surprised when this didn't work out of the box. I was expecting it to be a common need. I.e., I want 90% of popovers to be triggered with a click - but putting 'data-tippy-trigger' on an element to override it. I thought that would be the default behavior.

Here is the addon in v5 - should be easier to grok now that it's in its own file, if you want to make a PR to fix

Was this page helpful?
0 / 5 - 0 ratings