Replies: 2 comments
-
There could be 2 checks:
Point 1 is quite simple to implement. You can P.2, however, is more tricky and has edge cases. What if <ParentComponent>
<Container>
<SlotedComponent />
</Container>
</ParentComponent> If this is not valid and More edge case here is dynamic content, e.g. <ParentComponent>
<template v-if="foo">
<SlotedComponent />
<SlotedComponent />
</template>
<SlotedComponent v-else />
</ParentComponent> In this case you need to check Nevertheless, by design in Vue component should not know that it has in its slot. It just has a place to render passed content. |
Beta Was this translation helpful? Give feedback.
-
Yes, there is ways to make it work at runtime. But I think for a best DX would be to have the error pop in the IDE. Should the check be recursive ? I don't know, I'd say no and each component should check for its direct children.
|
Beta Was this translation helpful? Give feedback.
-
To make Component with slots more consistent, it would be great to be able to restrict the SlotedComponent to certain type of component.
Would be neat to be able in ParentComponent to type its slots, so you could restrict slots to ComponentA | ComponentB, and if you are passing ComponentC or just a string it create and error (at least in the IDE).
I thought defineSlots's return types would do that, but it seems to be a not fully working feature (or I did not understand defineSlots which could be the case).
I am aware that I could theoricaly do this with props, and it actually works fine that way. But I think it make more sense "visually" to pass it with slots as it will be rendered.
Beta Was this translation helpful? Give feedback.
All reactions