chore(vue): allow adding events in jsx templates (#12746)
This commit is contained in:
parent
61c66bb82b
commit
6b324d3780
|
|
@ -32,6 +32,7 @@ function render(component) {
|
||||||
if (typeof component === 'string')
|
if (typeof component === 'string')
|
||||||
return component;
|
return component;
|
||||||
const componentFunc = registry.get(component.type) || component.type;
|
const componentFunc = registry.get(component.type) || component.type;
|
||||||
|
const isVueComponent = componentFunc !== component.type;
|
||||||
|
|
||||||
const children = [];
|
const children = [];
|
||||||
const slots = {};
|
const slots = {};
|
||||||
|
|
@ -50,10 +51,15 @@ function render(component) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(component.props)) {
|
for (const [key, value] of Object.entries(component.props)) {
|
||||||
if (key.startsWith('v-on:'))
|
if (key.startsWith('v-on:')) {
|
||||||
listeners[key.substring('v-on:'.length)] = value;
|
const event = key.substring('v-on:'.length);
|
||||||
else
|
if (isVueComponent)
|
||||||
|
listeners[event] = value;
|
||||||
|
else
|
||||||
|
props[`on${event[0].toUpperCase()}${event.substring(1)}`] = value;
|
||||||
|
} else {
|
||||||
props[key] = value;
|
props[key] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,3 +51,12 @@ test('named slots should work', async ({ mount }) => {
|
||||||
await expect(component).toContainText('Main Content')
|
await expect(component).toContainText('Main Content')
|
||||||
await expect(component).toContainText('Footer')
|
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();
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue