10000 Pass events to dynamic components · Issue #5265 · sveltejs/svelte · GitHub
[go: up one dir, main page]

Skip to content
Pass events to dynamic components #5265
Closed
@rottmann

Description

@rottmann

Is it possible to pass events to dynamic components?
E.g. pass on:click as props and recieve the click event.

Made a full exmaple: https://svelte.dev/repl/a16dd36f0265408a9c42409986b44acd?version=3.24.1

Short Version:

Example.svelte

<script>
  export let component
  export let props
</script>

<svelte:component
  this={component}
  {...props}
></svelte:component>

Example call

<script>
import Example from './Example.svelte'
const component = ... // some svelte component e.g. a Button
const props = {
  'on:click' = (e) => console.log('THIS SHOULD BE CALLED')
}
</script>

<Example {component} {props}></Example>

The on:click will not be triggered, only if i wrote it like this

<Example {component} {props} on:click={(e) => props['on:click'](e)}></Example>

But in this case i have to call the click targets manually.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0