rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Conditional Slots

Open tanhauhau opened this issue 2 years ago • 3 comments

rendered

Related issues:

  • https://github.com/sveltejs/svelte/issues/5604
  • https://github.com/sveltejs/svelte/issues/6059
  • https://github.com/sveltejs/svelte/issues/7651

tanhauhau avatar Apr 12 '22 02:04 tanhauhau

@tanhauhau Sounds like this might be able to handle $$slots with slot forwarding?

techniq avatar May 06 '22 03:05 techniq

@tanhauhau Sounds like this might be able to handle $$slots with slot forwarding?

@techniq yea, so you would write:

<Field>
   {#if $$slots.label}
	<slot name="label" slot="label" />
   {/if}
   {#if $$slots.description}
	<slot name="description" slot="description" />
   {/if}
</Field>

tanhauhau avatar May 06 '22 04:05 tanhauhau

I would also very much like to see this added to resolve the same issue mentioned above, a rather common issue when working with slots in Svelte: $$slots with slot forwarding

brandonmcconnell avatar Aug 01 '22 21:08 brandonmcconnell

I am very much in need of this as forwarded slots as currently implemented is pretty broken with no work-around for checking of content. See: https://svelte.dev/repl/1757f88780b644519bb30c2b68b10873?version=3.55.1

TristanBrotherton avatar Feb 17 '23 22:02 TristanBrotherton

Any reason this hasn't been merged yet? I also need this.

risalfajar avatar Mar 23 '23 20:03 risalfajar

Conditional slots will be possible in Svelte 5 through snippets and render tags. Whether or not we want to add syntax sugar with if+snippet inside remains to be seen. Closing this RFC - thank you.

dummdidumm avatar Nov 16 '23 16:11 dummdidumm

@dummdidumm @tanhauhau

Outside of Svelte 5, this PR introduces a valuable and foundational solution to slot forwarding across both methodologies — with and without runes — simply by using {#if}.

Could we merge this in addition to the other very welcome solutions?

Thanks!

brandonmcconnell avatar Nov 16 '23 18:11 brandonmcconnell