Open pareeohnos opened 4 years ago
I think we need to document this as a caveat. A similar one exists in portal-vue.
The basic reason for needing 2 ticks is that the portal content itself it mounted on the first tick after the parent of the portal has rendered - and mounting will introduce another tick until the ref is actually in the DOM.
I've run into a similar issue to #14 but the fix in there hasn't worked for me. I've got a dropdown component which is using the library
popper.js
to manage the position of the element, and I'm looking to get this bit to render in the portal. My template looks like thisThe
.dropdown
element has a ref that I need to be able to use in order to initialise the popper library. This is being handled when the user clicks on the triggerI've kept the console logs to show where I'm having issues, but basically both before the
$nextTick
call and after it, the dropdown ref is undefined.In issue #14 the fix was to wait for the next tick but this isn't working here
Update
As a workaround, I've tried setting an
id
on the dropdown div, and found some unusual behaviour. Unsure whether this is related to the way portal is implemented, or our own code, but I have to wait for at least 2 ticks for it to work, or alternatively usesetTimeout(fn, 0);
This result in no element being output, but this works
Or this
Both kinda feel like nasty hacks but this is the only thing that seems to be working for me