Using JSX in custom directives
Suppose you want to create a convenient tooltip directive that can be easily used by providing only the content of it. This works fine for simple tooltips. However, what if you want to create more complex, custom tooltips? For example, you want to wrap the element as a trigger and use it in combination with a component from libraries like https://kobalte.dev/docs/core/components/tooltip or https://corvu.dev/docs/primitives/tooltip
https://playground.solidjs.com/anonymous/eb41151c-59ca-460f-aa45-26ea80525e01
Is it possible to use JSX inside the directive to wrap the
<button>
with a <Tooltip>
component?6 Replies
You cannot directly influence the return value, but you can create a portal for the tooltip and event listeners for the trigger.
How would you create a portal? What do you mean? Using
document.appendChild()
?Basically, you call
Portal({ get children() { return <Tooltip .../> } })
.I came up with this. However, it renders the whole element as a
<Portal>
. Can you render it in the same exact spot?
Unfortunately, no, but you can use the ref to move the tooltip.
I came up with this, but now it seems like you need to re-invent the whole
<Tooltip>
component