Tippyjs: Using Tippy.js v5.1.2, I am not able to call the tippy() fn with cytoscape.js to create a tooltip

Created on 18 Dec 2019  路  12Comments  路  Source: atomiks/tippyjs

I get an error about a plain object being passed, but I get the error with a plain object and a ref object.

validation.ts:61 Uncaught Error: tippy() was passed a plain object which is no longer supported as an
argument.

See https://atomiks.github.io/tippyjs/misc/#custom-position
at throwErrorWhen (validation.ts:61)
at validateTargets (validation.ts:81)
at tippy (index.ts:28)
at makePopper (pen.js:44)
at pen.js:63
at fa.forEach (cytoscape.min.js:23)
at $a. (pen.js:62)
at o (cytoscape.min.js:23)
at cytoscape.min.js:23
at Ai (cytoscape.min.js:23)

This is the code I'm calling where ele is a cytoscape.js element.
I'm also not sure what to pass for the clientWidth, clientHeight, or getBoundingRectClient(). The docs on this are not clear to me. I have a codePen located herer:
Tippy v5
function makePopper(ele) {
let ref = ele.popperRef();
tippy(ele, {
// popperInstance will be available onCreate
lazy: false,
onCreate(instance) {
instance.popperInstance.reference = {
clientWidth: 10,
clientHeight: 10,
getBoundingClientRect() {
return {
w: 20, h:20
};
},
};
},
});
}

馃挕 question

All 12 comments

You want something like this:

    let ref = ele.popperRef();
    // Pass a placeholder element that doesn't do anything
    ele.tippy = tippy(document.createElement('div'), {
      // popperInstance will be available onCreate
      lazy: false,
      hideOnClick: false,
      onCreate(instance) {
        instance.popperInstance.reference = ref;
      },
    });

The posted code gives this error:


Uncaught TypeError: Cannot read property 'show' of undefined
    at Oe.<anonymous> (pen.js:61)
    at o (cytoscape.min.js:23)
    at cytoscape.min.js:23
    at Ai (cytoscape.min.js:23)
    at Ni.zi.emit.zi.trigger (cytoscape.min.js:23)
    at Oe.emit (cytoscape.min.js:23)
    at n (cytoscape.min.js:23)
    at cytoscape.min.js:23

That minified "anonymous" function at the beginning is this:
mount (tippy.chunk.esm.js:1470)
at Object.show(tippy.chunk.esm.js:1694)

https://codepen.io/atomiks/pen/WNbpEwx?editors=1010

You need to set it onShow, looks like setting it onCreate doesn't successfully set it 馃

drag event lets you update the popperInstance

I have altered the code as suggested, with some minor modifications. The Tippy is showing above the node the first time I hover over the Node, but the next time it appears at the far left of the screen. It seems to lose the position it had when it was first shown after it is hidden on mouseout. How can I make the Tippy retain its position over the node and in fact track with the node when the node is dragged around the screen.

function makePopper(ele) { let ref = ele.popperRef(); ele.tippy = tippy(document.createElement('div'), { // popperInstance will be available onCreate lazy: false, hideOnClick: false, onCreate(instance) { instance.popperInstance.reference = ref }, }); ele.tippy.setContent('Node ' + ele.id()); }

Look at the CodePen - it does that. But onCreate should still work, I'll have to take a look to see what's causing that bug.

Ok, thank you, I just saw your post about the same time as mine. Yes, I see that the on show is working and the tippy tracks the node with the drag event. One additional issue I see is the edge tippy is shown when hovering over the edge, but does not track the movement when dragged.

Yeah I'm guessing the edge doesn't fire a drag event. You'll have to look through their docs to see what the event is for moving the edge and use that to update the instance as well.

Also sticky: true should be able to work which prevents the need to manually call .update(), but it uses the "placeholder element" not the popper ref object, so it doesn't work. I'll have to fix that one as well.

Ok, thank you for the responses.

Will you create bugs for the onCreate and sticky: true issues? Or should I do that? I am interested in following the solution.

I've pushed fixes for them already :-)

I am working on something else currently. I want to batch these changes into 5.2.0

5.1.3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

makarov906 picture makarov906  路  4Comments

faroukcharkas picture faroukcharkas  路  4Comments

mreinstein picture mreinstein  路  5Comments

skazhikadyadya picture skazhikadyadya  路  3Comments

kmanolis picture kmanolis  路  4Comments