KABBOUCHI / vue-tippy

VueJS Tooltip powered by Tippy.js
https://vue-tippy.netlify.app
MIT License
722 stars 86 forks source link

How to programatically show/hide tooltip? #285

Open ammojamo opened 1 year ago

ammojamo commented 1 year ago

I'm trying to get a tooltip to show/hide based on some boolean condition instead of on hover.

I see the docs say to pass trigger: 'manual' to programatically show/hide a tooltip, but I can't figure out how to actually show/hide it after passing that config.

nip10 commented 1 year ago

I also couldn't find this in the docs, so I looked for similar issues. I was able to make this work by using a ref and calling the show and hide methods. I then expose the methods to the parent component

import { Tippy } from 'vue-tippy'

const tippyRef = ref<typeof Tippy | null>(null)
const showPopover = () => {
  tippyRef.value?.show()
}
const hidePopover = () => {
  tippyRef.value?.hide()
}

<tippy ref="tippyRef" trigger="manual">
...
</tippy>