Skip to content

docs: fix attribute example in basic markup #8813

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

Merged
merged 2 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions documentation/docs/02-template-syntax/02-basic-markup.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ An expression might include characters that would cause syntax highlighting to f
When the attribute name and value match (`name={name}`), they can be replaced with `{name}`.

```svelte
<!-- These are equivalent -->
<button {disabled}>...</button>
<button {disabled}>...</button>
<!-- equivalent to
<button disabled={disabled}>...</button>
-->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be wrong, I'll create a PR to fix this.

```

By convention, values passed to components are referred to as _properties_ or _props_ rather than _attributes_, which are a feature of the DOM.
Expand Down
11 changes: 6 additions & 5 deletions documentation/docs/02-template-syntax/05-element-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ The simplest bindings reflect the value of a property, such as `input.value`.
<input type="checkbox" bind:checked={yes} />
```

If the name matches the value, you can use shorthand.
If the name matches the value, you can use a shorthand.

```svelte
<!-- These are equivalent -->
<input bind:value />
<input bind:value />
<!-- equivalent to
<input bind:value={value} />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, or are you doing this to ensure Prettier doesnt pick it up?

-->
```

Numeric input values are coerced; even though `input.value` is a string as far as the DOM is concerned, Svelte will treat it as a number. If the input is empty or invalid (in the case of `type="number"`), the value is `undefined`.
Expand Down Expand Up @@ -339,8 +340,8 @@ A `class:` directive provides a shorter way of toggling a class on an element.

```svelte
<!-- These are equivalent -->
<div class={active ? 'active' : ''}>...</div>
<div class:active>...</div>
<div class={isActive ? 'active' : ''}>...</div>
<div class:active={isActive}>...</div>

<!-- Shorthand, for when name and value match -->
<div class:active>...</div>
Expand Down