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.svelte

19 lines
375 B

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