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')
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue