This is a continuation of https://discord.com/channels/830184174198718474/1443695518927552574
Is there a way to only conditionally provide a default slot to a component?
Currently, we have to do this:
{section.data.title && section.data.subtitle && !section.data.description && (
<TopicHeader
subtitle={section.data.subtitle}
title={section.data.title}
level="h2"
/>
)}
{section.data.title && section.data.subtitle && section.data.description && (
<TopicHeader
subtitle={section.data.subtitle}
title={section.data.title}
level="h2"
>
{section.data.description}
</TopicHeader>
)}
The following does not work, as astro already creates a default slot, even when it's empty:
{section.data.title && section.data.subtitle && (
<TopicHeader
subtitle={section.data.subtitle}
title={section.data.title}
level="h2"
>{
section.data.description && <Fragment slot="default">{section.data.description}</Fragment>
}</TopicHeader>
)}
switching to a named slot doesn't seem to work either:
{section.data.title && section.data.subtitle && (
<TopicHeader
subtitle={section.data.subtitle}
title={section.data.title}
level="h2"
>
{section.data.description && <Fragment slot="description">{section.data.description}</Fragment>}
</TopicHeader>
)}
with checking for it like so:
{Astro.slots.has('description') && (
<p class="mt-6 max-w-lg text-lg sm:text-xl text-balance leading-relaxed empty:hidden">
<slot name="description" />
</p>
)}
Will still render an empty <p> tag.
And yes, i checked that the description is actually undefined. Rendering {JSON.stringify(Astro.slots)} also reveals description to be true.