mirror of https://github.com/sveltejs/svelte
overwrite this in custom event handlers - fixes #1297
parent
ed605bfa79
commit
1fb4041519
@ -0,0 +1,22 @@
|
|||||||
|
export default {
|
||||||
|
html: `<input>`,
|
||||||
|
|
||||||
|
test(assert, component, target, window) {
|
||||||
|
const input = target.querySelector('input');
|
||||||
|
const event = new window.KeyboardEvent('keydown', {
|
||||||
|
which: 13
|
||||||
|
});
|
||||||
|
|
||||||
|
let blurred = false;
|
||||||
|
|
||||||
|
input.focus();
|
||||||
|
|
||||||
|
input.addEventListener('blur', () => {
|
||||||
|
blurred = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
input.dispatchEvent(event);
|
||||||
|
|
||||||
|
assert.ok(blurred);
|
||||||
|
},
|
||||||
|
};
|
@ -0,0 +1,23 @@
|
|||||||
|
<input on:enter='this.blur()'>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
events: {
|
||||||
|
enter(node, callback) {
|
||||||
|
function handleKeydown(event) {
|
||||||
|
if (event.which === 13) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
node.addEventListener('keydown', handleKeydown);
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy() {
|
||||||
|
node.removeEventListener('keydown', handleKeydown);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
Reference in new issue