Skip to content

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

Closed
kevmodrome opened this issue Apr 20, 2021 · 5 comments
Closed

Ability to conditionally use slots #6218

kevmodrome opened this issue Apr 20, 2021 · 5 comments

Comments

@kevmodrome
Copy link
Contributor

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 value This should show up!.

Describe alternatives you've considered
One workaround is to do the conditional outside of the slot, like so:

{#if showContent}
    <Item />
{/if}

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.

@j3rem1e
Copy link

j3rem1e commented Apr 20, 2021

Personally I like the way it is now, and implementing that will be a big breaking change.

@kevmodrome
Copy link
Contributor Author

Personally I like the way it is now, and implementing that will be a big breaking change.

Why?

@j3rem1e
Copy link

j3rem1e commented Apr 20, 2021

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.

@stale
Copy link

stale bot commented Oct 17, 2021

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.

@stale stale bot added the stale-bot label Oct 17, 2021
@stale
Copy link

stale bot commented Oct 31, 2021

This issue has been closed as it was previously marked as stale and saw no subsequent activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants