Using named slot is not working as I expected. #12733
Unanswered
gio-hernandez-saito
asked this question in
Q&A
Replies: 2 comments 2 replies
-
I figured out that this problem is discussed before here and here. I think this is about $$slots with slot forwarding. Now I just added boolean flag to solve the issue, and it worked although the code is not that good as I expected. While using Svelte 4, is there no choice but to use a workaround like this? {#if $props.hasHeaderAbove && $$slots['header-above']}
<Base className="flex-none">
<slot name="header-above" />
</Base>
{/if} |
Beta Was this translation helpful? Give feedback.
0 replies
-
In this case // LayoutCard
<BaseCard passedProps="{baseCardProps}">
<slot name="header-above" slot="header-above" />
<!-- other codes ... -->
</BaseCard>
// usage
<LayoutCard passedProps="{layoutCardProps}">
</LayoutCard> you are always passing a slot to // LayoutCard
<BaseCard passedProps="{baseCardProps}">
{#if $$slots['header-above']}
<slot name="header-above" slot="header-above" />
{/if}
<!-- other codes ... -->
</BaseCard>
// usage
<LayoutCard passedProps="{layoutCardProps}">
</LayoutCard> |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I'm trying to create a card component with svelte.
I'm using unoCSS and sveltekit, and I faced a problem with using named slots.
So, the code above is a BaseCard component, which has no styles. I want to activate inner div class only when the slot is used.
And the code below is StyledCard component.
But, if I use StyledCard component without an 'header-above' slot, the 'header-above-class' appears, which means the gap-4 is applied. And also, console.log($$slots) shows { header-above: true }
Is there any solution for that? I think I need to change LayoutCard logic.
Beta Was this translation helpful? Give feedback.
All reactions