-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add documentation for $$slots #5277
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
Add documentation for $$slots #5277
Conversation
Thank you @CMessinides, it looks better now 👍 |
@@ -1289,6 +1289,27 @@ Named slots allow consumers to target specific areas. They can also have fallbac | |||
</div> | |||
``` | |||
|
|||
--- | |||
|
|||
`$$slots` is an object whose keys are the names of the slots passed into the component by the parent. If the parent leaves a named slot empty, `$$slots` will not have a key for that slot. This allows components to render a slot (and other elements, like wrappers for styling) only if the parent provides children for it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite true. If a slot is explicitly passed with no content, $$slots.foo
will still be present. This is basically what #5312 is asking for, and I'm not sure how that's going to be handled yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I updated to make the difference between omitted slots and empty slots more clear. My language feels a little strained in this sentence:
If the parent does not pass in a slot with a particular name, that name will not be a present in
$$slots
.
I was trying to avoid saying "If the parent does not pass in a named slot," which sounds ambiguous to my ear -- could be misinterpreted as "If the parent does not pass in any named slots." But I'm not sure if "a slot with a particular name" is the best way to describe what we mean, either. Feedback appreciated.
I also added a note under the $$slots
code sample to hammer home the behavior for explicitly empty slots, which may or may not be necessary -- feedback also appreciated on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See inline comment. We should be careful about distinguishing between not passing a slot and passing a slot with no content.
@Conduitry Thank you for your review and feedback. Please see my edits and my reply to your inline comment, and let me know if these changes line up with what you were thinking. |
Sorry about the long delay! This looks awesome, thank you. I made a couple of small tweaks, am merging now, and will redeploy the site shortly. |
No worries about the delay! Glad I could help :) |
Fixes #5266
Changes
$$slots
.$$slots
under the named slot section of the API documentation.I pulled my explanation of
$$slots
from the original PR (#4602) -- @tanhauhau thank you for the write up, and if I've misunderstood anything about the implementation, please don't hesitate to let me know. :)Caveats
The tutorial chapter isn't running correctly yet -- the REPL halts on the following error:
I could get it working in the REPL using the local version, so I'm assuming this issue will be revolved when the latest version of the REPL is published?