solid icon indicating copy to clipboard operation
solid copied to clipboard

add withoutContainer to `<Portal>` options

Open Danue1 opened this issue 3 years ago • 8 comments

I just want to render without containers. First of all, this is the design, if there is a better way, that's fine.

Summary

Before.

  • We have to render <Portal> with container(<div> or <g>) into mount.

After.

  • We can render <Portal> without container into mount.

Danue1 avatar Sep 12 '22 18:09 Danue1

The challenge here is this won't forward events properly. We use that element as a mechanism to forward delegated events. I gave the head some special treatment as it isn't expected to attach event listeners to it. But for typical insertions, we need the element the way it works currently.

ryansolid avatar Sep 12 '22 19:09 ryansolid

https://github.com/solidjs/solid/blob/28ca71f38b77bb4b78917830db1fe391711eac07/packages/solid/web/src/index.ts#L93-L97

Is it because we can't pass a getter like host? In that case, containers like <div>, <g> seem inevitable. Am I understanding correctly?

Danue1 avatar Sep 13 '22 06:09 Danue1

Sorry to waste your time, but how could there be no way? At the very least, it would be nice to be able to style the container.

Danue1 avatar Sep 13 '22 06:09 Danue1

Alternatively, specifying the container with the desired tag seems fine to me. I hope for your insights.

Danue1 avatar Sep 13 '22 06:09 Danue1

I mean it isn't impossible it is just tricky, we'd need to try to collect any top level elements even as they changed. Right now the escape hatch is Portal has a ref to the container. But It might be interesting passing other attributes through. Just have absolutely no idea how that'd play with TypeScript.

ryansolid avatar Sep 13 '22 19:09 ryansolid

Passing other attributes? If we think of something like <Portal classList={{ foo, bar }}>...</Portal>, is that correct?

Danue1 avatar Sep 14 '22 16:09 Danue1

Yes that's what I'm thinking.

ryansolid avatar Sep 14 '22 19:09 ryansolid

Thanks, I'll try it.

Danue1 avatar Sep 15 '22 11:09 Danue1