-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Ability to conditionally use slots #6218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Personally I like the way it is now, and implementing that will be a big breaking change. |
Why? |
For example, using the VirtualList component in the svelte organization https://github.com/sveltejs/svelte-virtual-list/blob/master/VirtualList.svelte#L166 VirtualList (largely simplified) : {#each getVirtualItems() as item}
<slot {item}>Template not set</slot>
{/each} MyComponent <VirtualList let:item>
{#if isVisible(item)}
{item.name}
{/if}
</VirtualList> I don't want the default slot to be rendered here. It's just an example of code which will break with this issue. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been closed as it was previously marked as stale and saw no subsequent activity. |
I recently ran into this issue where I want to conditionally check if there's a default slot applied to the component. This currently can't be done without working around the current implementation.
It's a bit hard to explain but here's a REPL for clarity: https://svelte.dev/repl/6d51332a90e54c658647e7c1aaff9359?version=3.37.0
On the second instance of
Item
I expect it to use the fallback valueThis should show up!
.Describe alternatives you've considered
One workaround is to do the conditional outside of the slot, like so:
This works but gets pretty wild once you start adding props to the equation.
How important is this feature to you?
It's a nice-to-have since it can be worked around. It's not something I run into every day.
The text was updated successfully, but these errors were encountered: