Svelte: bind window mouseenter/leave events to document

Created on 19 May 2018  Â·  2Comments  Â·  Source: sveltejs/svelte

The mouseenter and mouseleave events are very useful, but don't seem to do anything when bound to window. Instead you have to bind them to document. Since we have a <svelte:window> element, I wonder if this...

<svelte:window on:mouseleave="handleMouseleave()"/>

...should translate to this:

document.addEventListener('mouseleave', () => {
  component.handleMouseleave();
});

Most helpful comment

Going with <svelte:document> was the right move — implemented in 2.15. Thanks

All 2 comments

That would be a bit weird. Maybe it would make sense to have a <svelte:document> instead, if there were any other events worth binding…?

Recently I searched the docs for <svelte:document>, I ended up doing

oncreate() {
  document.addEventListener('mouseenter', someHandler)
  // ..
}

which seemed just fine.

Going with <svelte:document> was the right move — implemented in 2.15. Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matt3224 picture matt3224  Â·  3Comments

bestguy picture bestguy  Â·  3Comments

clitetailor picture clitetailor  Â·  3Comments

robnagler picture robnagler  Â·  3Comments

ricardobeat picture ricardobeat  Â·  3Comments