You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/window-event-custom/main.html

25 lines
442 B

<svelte:window on:esc="set({ escaped: true })" />
<p>escaped: {escaped}</p>
<script>
export default {
data() {
return { escaped: false };
},
events: {
esc(node, callback) {
function onKeyDown(event) {
if (event.which === 27) callback(event);
}
node.addEventListener('keydown', onKeyDown);
return {
destroy() {
node.removeEventListener('keydown', onKeyDown);
}
};
}
}
};
</script>