Skip to content

Commit

Permalink
Update 06-component-directives.md on:event clarification
Browse files Browse the repository at this point in the history
later examples changed to handle the `hello` and `click` events dispatched/forwarded by earlier examples

added note about only events forwarded by direct children can be listened to
  • Loading branch information
cloudymeatball committed Jan 4, 2024
1 parent 94aab90 commit 03f17d3
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ Components can emit events using [`createEventDispatcher`](/docs/svelte#createev
Listening for component events looks the same as listening for DOM events:

```svelte
<SomeComponent on:whatever={handler} />
<SomeComponent on:hello={helloHandler} on:click={clickHandler} />
```

As with DOM events, if the `on:` directive is used without a value, the event will be forwarded, meaning that a consumer can listen for it.

```svelte
<SomeComponent on:whatever />
<SomeComponent on:hello on:click />
```

> Components can only listen to events forwarded by their direct child components or elements.
## --style-props

```svelte
Expand Down

0 comments on commit 03f17d3

Please sign in to comment.