Replies: 2 comments
-
My short answer recommendation would just be to use x-show if you can. Longer answer is if you really want to use tippy within x-if or x-for you probably have to do something to initialize it after it's been inserted into dom by Alpine. You could try something like
or you could do similar with x-effect. I've never used Tippy just glanced at docs now. We do use Popper JS which has similar API and we do memoize popper instance with component and initialize it in $nextTick using $refs but it's doing fetches to get preview so it's probably too complicated of example to be useful for you. |
Beta Was this translation helpful? Give feedback.
-
This works -- awesome! Thanks. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Loving Alpine. We're building something pretty great (we hope) with it but I've run into the following issue:
Maybe I'm missing something very basic but can't seem to get the tooltip lib Tippy to work within Alpine's x-if, x-for, and x-bind attributes. I don't get any error messages or anything, it's just being ignored.
Tippy (v6.x, using CDN dev) works great otherwise but anything inside either an x-for loop or a conditional x-if statement or inserted using :class is just ignored. I've tried both the
<button data-tippy-content="Normal cupcake">Text</button>
+tippy('[data-tippy-content]');
approach as well as the ...class="tippyNormal"
andtippy('.tippyNormal', { content: 'Normal cupcake', });
So for me, the following works great:
but not:
What we think is going on -- (do let me know if this isn't right!) With Alpine.js, tags can only have a single child structure, and this structure isn't in the DOM until the template is run. Hence, with Alpine, if you have:
As long as
cupcake == false
,getElementsByClassName('tippyCupcake')
will return undefined, as there's no element in the DOM that has the class nametippyCupcake
. Oncecupcake == true however
, the div gets inserted into the DOM.So I wonder if what's going on is that when Tippy is initialized it:
So when id/class/etc="tippyCupcake" above gets inserted into the DOM, there's no way for tippy to know as it has already done its parsing.
But how come Tippy works with x-show but not with x-bind, x-for, and x-if?
So regardless if the above is true, is there a way to get Tippy to work with Alpine? Can we manually ask Tippy to re-crawl the DOM or is there any other way to get Tippy running with Alpine?
(posted this on Tippy's GitHub board too but no response there so far)
Thanks for any help!
Beta Was this translation helpful? Give feedback.
All reactions