Skip to content

docs: clarify ordering of attributes and props #15805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions documentation/docs/03-template-syntax/01-basic-markup.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,27 @@ As with elements, `name={name}` can be replaced with the `{name}` shorthand.
<Widget foo={bar} answer={42} text="hello" />
```

_Spread attributes_ allow many attributes or properties to be passed to an element or component at once.
## Spreading

_Spreading_ allow many attributes or properties to be passed to an element or component at once.

An element or component can have multiple spread attributes, interspersed with regular ones.

```svelte
<Widget {...things} />
<button {...attributes}>...</button>
<button {...attributes} type="button">...</button>
<Widget {...props} />
<Widget {...props} foo={bar} text="hello" {...aria} />
```
The order in which they are displayed matters

```svelte
<script>
const attributes = { type: "button" };
</script>

<button {...attributes} type="submit">...</button> <!-- type is "submit" -->
<button type="submit" {...attributes}>...</button> <!-- type is "button" -->
```

## Events
Expand Down