How to trigger tippyjs tooltip on a fabricjs object inside canvas

Viewed 251

I am trying to create some tooltips with TippyJS on a FabricJS canvas but keep getting the error that the selectors I use are not valid.

Normally this is how I trigger a tooltip with Tippy:

$( ".hoverimagetip" ).each(function( i ) {
    tippy(this, {
        theme: 'blue',
        trigger: 'mouseenter',
        allowHTML: true,
        followCursor: 'initial',
        animation: 'scale-subtle',
        interactive: true,
        content: function (reference) {
            return reference.querySelector('.tooltipcontent');
        }
    });
});

But now I want to trigger the tooltip when clicking an object inside the canvas, in this case cirkel1 so I tried the following (after creating cirkel1 and adding it to the canvas):

cirkel1.on('mousedown', ()=>{
  tippy(this, {
        theme: 'blue',
        trigger: 'mouseenter',
        allowHTML: true,
        followCursor: 'initial',
        animation: 'scale-subtle',
        interactive: true,
        content: function (reference) {
            return reference.querySelector('.tooltipcontent');
        }
    });
});

But when clicking the circle I get this error in my console:

tippy.js@6:1 Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': '#<fabric.Circle>' is not a valid selector.

What is the correct way to do this?

Codepen with entire code: https://codepen.io/twan2020/pen/mdOWgaG

0 Answers
Related