chore(vue): allow adding events in jsx templates (#12746)

This commit is contained in:
Pavel Feldman 2022-03-15 12:02:10 -08:00 committed by GitHub
parent 61c66bb82b
commit 6b324d3780
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View file

@ -32,6 +32,7 @@ function render(component) {
if (typeof component === 'string')
return component;
const componentFunc = registry.get(component.type) || component.type;
const isVueComponent = componentFunc !== component.type;
const children = [];
const slots = {};
@ -50,10 +51,15 @@ function render(component) {
}
for (const [key, value] of Object.entries(component.props)) {
if (key.startsWith('v-on:'))
listeners[key.substring('v-on:'.length)] = value;
else
if (key.startsWith('v-on:')) {
const event = key.substring('v-on:'.length);
if (isVueComponent)
listeners[event] = value;
else
props[`on${event[0].toUpperCase()}${event.substring(1)}`] = value;
} else {
props[key] = value;
}
}
}

View file

@ -51,3 +51,12 @@ test('named slots should work', async ({ mount }) => {
await expect(component).toContainText('Main Content')
await expect(component).toContainText('Footer')
})
test('slot should emit events', async ({ mount }) => {
let clickFired = false;
const component = await mount(<DefaultSlot>
<span v-on:click={() => clickFired = true}>Main Content</span>
</DefaultSlot>);
await component.locator('text=Main Content').click();
expect(clickFired).toBeTruthy();
})