From 44b67e46b90ee0cacf0e85b94fbb968b58704e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20K=C3=BCgler?= Date: Mon, 31 Jul 2023 21:28:18 +0200 Subject: [PATCH] Add support for as a child (issue #123 in 6.x) Having as a child of an element to tooltip was a nice use-case in 4.x. See https://github.com/KABBOUCHI/vue-tippy/issues/123. We re-add this in a similar manner. Using to="parent" (as a fixed string), one can now use either the main slot ("default") or its specific "content" slot to specify the tooltip content. The tooltip will be triggered on the parent element without adding a specifc Tippy node to the DOM. This should provides a non-interfering way to specify tooltips. Implementation: For the to="parent" case, we need to find the parent DOM element, but in the "worst" case won't render any DOM nodes at all, which could help us to find the parent. Instead, we initially render a hidden (and the tooltip content). Using the span as a template ref ('findParentHelper'), we can get the parent and assign that to the actual 'elem' ref. This will trigger a re-render, where we can drop the helper again. --- docs/content/en/flavor/component.md | 14 ++++++++++++ playground/pages/Index.vue | 27 +++++++++++++++++++++++ src/components/Tippy.ts | 34 ++++++++++++++++++++++++++--- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/docs/content/en/flavor/component.md b/docs/content/en/flavor/component.md index e278834..5fcc86a 100644 --- a/docs/content/en/flavor/component.md +++ b/docs/content/en/flavor/component.md @@ -70,6 +70,20 @@ Mount tippy on the child node instead of default tag ``` + +### Example 3 +Tippy as a child using `to="parent"`. \ +Works like `:tag="null"`, but applies the tooltip to the parent element instead of the child. + +```html + +``` + ## Singleton ### Example 1 diff --git a/playground/pages/Index.vue b/playground/pages/Index.vue index be5e8fb..b53672d 100644 --- a/playground/pages/Index.vue +++ b/playground/pages/Index.vue @@ -88,6 +88,33 @@ +
+ Tippy as a child component with prop content: + + +
+ +
+ Tippy as a child component with #content template: + + +
+ +
+ Tippy as a child component with direct content: + + +
+
useTippy + callbacks(console.log):