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

20 lines
380 B

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