Slot introspection API — conditionally render wrappers based on slot content #340
WadihAchkar
started this conversation in
Proposals For Qwik
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What is it about?
A way to check whether a named slot has projected content, so components can conditionally render wrapper elements instead of always outputting empty DOM nodes.
What's the motivation for this proposal?
Problem I'm trying to solve:
Components with optional named slots (e.g. prefix/suffix icons in a Chip, optional headers/footers in a Card) are forced to always render wrapper elements around
<Slot />, even when no content is projected. This results in unnecessary empty DOM nodes.Example of the problem
Proposed Solution / Feature
A built-in hook or utility that allows checking whether a named slot has projected content.
For example:
Links / References
Here's how other frameworks such as Astro solved this problem:
Astro.slotsBeta Was this translation helpful? Give feedback.
All reactions