-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Programmatic Slot API & Slot "Sharing" #3730
Comments
If I'm not mistaken, this is possible. |
Ohhhh hey, look at that! Thanks @neoel, this is interesting. So I see what I was missing, and I kind of understand what's happening in your example... <svelte:self items={node.children} let:item={node}>
<slot item={node}>No slot</slot>
</svelte:self> It's almost like we need to repass the slot, which makes sense (even if it feels a bit redundant.) What I don't understand is why you're binding |
Good question! Might be nice for the docs to enlighten this further. So in the setup there's multiple slots. Since this is a recursive component I can imagine it being tricky to oversee all the slots and props passing. But It's making use of slot props First the Then in <svelte:self items={item.children} let:item={item}>
<!-- This slot will be passed to the nested Lists, and the item from the nested list will be passed to the original 'slot template' -->
nest <slot {item}>No slot</slot>
</svelte:self> This will make every nested list have n 'nest' strings before the original slot template. Hope this clears things up. |
Feature Request
I've been playing around with Svelte as a React/Vue alternative and it is absolutely stunning. That said, I quickly ran in to a few shortcomings of the
<slot>
implementation. Consider thisApp
The user very well might expect this to render a deep list in which every item is rendered inside a
<b/>
tag, per the passed slot. Now let's check out theList
component, which uses<svelte:self>
to recursively render deeply nested lists:At the moment this renders top-level items correctly. But sub-lists simply display a bunch of empty list items for. A pseudo-fix might be to add some default content to the slot:
But again, this doesn't actually address the intended use case outlined above!
Preferred Solution
I'd like to be able to access slot contents programmatically. I'd imagine something similar to how Vue, or how Svelte exposes the
$$props
object. (Which would allow me to bind the slot to each recursive instance!)Alternatives
I considered using props to pass a custom Svelte component, but it doesn't quite address my core interest of providing a component implementer a dead simple, flexible way to customize a component's content!
Priority
I'm intrigued by Svelte, but not using it in any production apps so this is far from pressing! (But if I were I'd say it's "quite important".)
Context
See also:
The text was updated successfully, but these errors were encountered: