rollup-plugin-svelte-svg icon indicating copy to clipboard operation
rollup-plugin-svelte-svg copied to clipboard

Event support

Open janosh opened this issue 4 years ago • 1 comments

It would be cool if SVG components supported events. Right now, something like this doesn't work:

<script>
import Icon from './my-icon.svg'
</script>

<Icon on:click={() => console.log(`hi`)} />

Instead, you need to wrap the SVG in a DOM element, e.g.

<span on:click={() => console.log(`hi`)}>
  <Icon />
</span>

Anything this package could do to enable the first version? Still learning how the Svelte compiler works so this might be a dumb question.

janosh avatar Nov 03 '20 16:11 janosh

I'm sure you understand the Svelte limitation that kept me from implementing this, and the issue you linked from reflects this. There's simply no way to lazily bind to all events / pass event listeners as props without defining all of them. There is now an rfc that might solve our problem: https://github.com/Sxxov/rfcs/blob/master/text/0000-spread-binding.md

I shall continue to leave this issue open until we can do this correctly in Svelte :) Thanks for the issue.

MKRhere avatar Aug 13 '21 09:08 MKRhere