-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[Feature] Component as slot #15900
Comments
Yes, I'm not sure I understand the text vs markup ambiguity in VTU, so we interpret slots as text there. Any reason you don't like JSX for composition? Looks way easier to read, is more in line with the way you compose in the actual |
I agree with your statements. However, my thought process is that it's another technology that adds to an already large stack of technologies that people are being pushed towards when using frontend frameworks. In my opinion there aren't many use cases where you want to add complex slots to your component (inside tests). I only do this when the parent component and child components are talking directly to each other which is rare. So the need for JSX is less. In addition, the API of JSX and the Vue template engine are not quite the same. In my opinion, those minor differences are confusing to people unfamiliar with JSX and most people using Vue don't use JSX. You probably know the differences but those are some of them: Vue Vue Vue Vue With that being said the mount options API isn't perfect either. As you said, the code does not look like how you would compose them in |
All the Vue examples you provide above are actually a subset of JSX, at least syntactically. The missing bits for the complete template support in slots would be:
|
I see that Vue 3 as a slot is done, but I can not make it to work. I see @sand4rt in your change, that you register the component globally in the app. But what If I don't want to register it globally, but just want to use it in one test as a slot? It doesn't render anything in that scenario. Something like that:
|
Hi @pbrzosko, i usually just register it globally for all tests, but if you want to register the component for one single test you could use: // playwright/index.ts
export type HooksConfig = {
components: Record<any, any>;
}
beforeMount<HooksConfig>(async ({ app, hooksConfig }) => {
for (const [name, component] of Object.entries(hooksConfig.components))
app.component(name, component);
}); // slots.test.ts
test('render a component as slot', async ({ mount }) => {
const component = await mount<HooksConfig>(DefaultSlot, {
slots: {
default: '<Button title="Submit" />',
},
hooksConfig: {
components: { Button }
}
});
await expect(component).toContainText('Submit');
}); |
But I believe there is a components object in mount options. Why it is not enough to specify a component there? |
I cannot specify a component as a slot:
TODO
The text was updated successfully, but these errors were encountered: