rfcs
rfcs copied to clipboard
Conditional Slots
Related issues:
- https://github.com/sveltejs/svelte/issues/5604
- https://github.com/sveltejs/svelte/issues/6059
- https://github.com/sveltejs/svelte/issues/7651
@tanhauhau Sounds like this might be able to handle $$slots with slot forwarding?
@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>
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
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
Any reason this hasn't been merged yet? I also need this.
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 @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!