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/site/content/tutorial/16-special-elements/03-svelte-window/text.md

464 B

title
<svelte:window>

Just as you can add event listeners to any DOM element, you can add event listeners to the window object with <svelte:window>.

On line 33, add the keydown listener:

<svelte:window on:keydown={handleKeydown}/>

Don't forget to add preventDefault modifier if you want to press any other key, e.g. after you have pressed Tab or Ctrl + D:

<svelte:window on:keydown|preventDefault={handleKeydown}/>