Merge pull request #1427 from sveltejs/dynamic-component-shorthand-event

fix handling of shorthand event handler in dynamic components
pull/1429/head
Rich Harris 7 years ago committed by GitHub
commit 53816ee5c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -364,7 +364,7 @@ export default class Component extends Node {
${this.handlers.map(handler => deindent`
function ${handler.var}(event) {
${handler.snippet}
${handler.snippet || `#component.fire("${handler.name}", event);`}
}
if (${name}) ${name}.on("${handler.name}", ${handler.var});

@ -0,0 +1 @@
<button on:click='fire("foo", { answer: 42 })'>click me</button>

@ -0,0 +1,18 @@
export default {
html: `
<button>click me</button>
`,
test (assert, component, target, window) {
const button = target.querySelector('button');
const event = new window.MouseEvent('click');
let answer;
component.on('foo', event => {
answer = event.answer;
});
button.dispatchEvent(event);
assert.equal(answer, 42);
}
};

@ -0,0 +1,9 @@
<svelte:component this={Widget} on:foo/>
<script>
import Widget from './Widget.html';
export default {
data: () => ({ Widget })
};
</script>
Loading…
Cancel
Save