Skip to content
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

Update slots.md #2806

Merged
merged 5 commits into from May 1, 2024
Merged

Update slots.md #2806

merged 5 commits into from May 1, 2024

Conversation

claushellsing
Copy link
Contributor

Update documentation in order to indicate how to use conditional render of default slot

Description of Problem

Proposed Solution

Additional Information

Update documentation in order to indicate how to use conditional render of default slot
Copy link

netlify bot commented Apr 18, 2024

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit a0a5326
🔍 Latest deploy log https://app.netlify.com/sites/vuejs/deploys/66321ac018d09b0008658007
😎 Deploy Preview https://deploy-preview-2806--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@brc-dd
Copy link
Member

brc-dd commented Apr 19, 2024

Can you provide more context on why this is needed? Isn't it obvious from the example above that, that $slots.foo is needed to check for <slot name="foo" />? Regarding the name when name is not explicitly specified, the docs mention:

A <slot> outlet without name implicitly has the name "default".

@brc-dd brc-dd added the state: awaiting-feedback Needs more input before further actions can be taken label Apr 19, 2024
@claushellsing
Copy link
Contributor Author

You're right. According to the documentation, one can interpolate knowledge and assume a $slots.default exists to check if the slot is present. However personally, I tend to prefer explicitness. It's just a personal preference.

@brc-dd
Copy link
Member

brc-dd commented Apr 19, 2024

Instead of two examples, can this be updated in the above example itself?

@claushellsing
Copy link
Contributor Author

Like this ?

In the example below we define a Card component with three conditional slots: header, footer and the default one.
When the header / footer / default is present we want wrap them to provide additional styling:

<template>
  <div class="card">
    <div v-if="$slots.header" class="card-header">
      <slot name="header" />
    </div>
    
    <div v-if="$slots.default" class="card-content">
      <slot />
    </div>
    
    <div v-if="$slots.footer" class="card-footer">
      <slot name="footer" />
    </div>
  </div>
</template>

@brc-dd
Copy link
Member

brc-dd commented Apr 19, 2024

Yeah, looks fine to me.

@NataliaTepluhina NataliaTepluhina merged commit cbe0bcb into vuejs:main May 1, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: awaiting-feedback Needs more input before further actions can be taken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants