Nested component slots

Hey all!

I understand that slots cannot be nested and I’m wondering 1) is there a good workaround that anybody has come across and 2) why isn’t this allowed?

Here is a simple example to illustrate what I’d like to do.

<.input_group>
  <:label>
    Password
    <:corner_hint>
      <a href="#">Forgot your password?</a>
    </:corner_hint>
  </:label>
</.input_group>

The :label slot simply passes it’s content to a .label component that has a :corner_hint slot.

Thanks in advance!

I don’t think there’s a way to know that is indeed happening, meaning there’s no way to enforce correctness. That enforcement however is one of the features heex wants to supply.

Also where would the support for nesting end?

1 Like

The assumption I had when I came across this issue was that maybe they hadn’t got to implementing support for it yet. I’ve personally felt like slot/3 is a little lacking right now. Maybe it just needs more time to bake and we’ll see support for things like this in the future. Not being able to nest slots seems like it really limits their utility so hopefully we’ll see it in the future.

Would still love any patterns or workarounds or best practices for this if anybody know of any.

1 Like