-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Implicit optional attributes #1637
Changes from 39 commits
7d330aa
f80566e
198567a
e48605e
0ed35ff
5b7ee05
f6571e1
f8adf9b
815147b
ec14013
692000a
907f05a
f2e6d99
0535bdc
8de3926
14a237a
110f789
57f6ad1
f062f65
63d4e0d
d9c9d52
dacafc6
b819ce6
3c36f3a
095d5d8
8e4d246
3891794
3fd536c
8089f06
637136a
707c1e7
d1b9f76
b317330
45d63a5
3ee805e
5f98c06
8037e78
dfe7ccb
e488e99
af93a08
9728825
390abdb
004ef9a
78a3129
ac09c97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,26 +15,36 @@ let level = 5; | |
let text = "Hello World!".to_owned() | ||
|
||
html! { | ||
<@{format!("h{}", level)} class="title">{ content }</@> | ||
<@{format!("h{}", level)} class="title">{ text }</@> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be better if the tests were executed 😞 |
||
} | ||
``` | ||
|
||
## Optional attributes for HTML elements | ||
|
||
Most HTML attributes can be marked as optional by placing a `?` in front of | ||
the `=` sign. This makes them accept the same type of value as otherwise, but | ||
wrapped in an `Option<T>`: | ||
Most HTML attributes can use optional values (`Some(x)` or `None`). This allows | ||
cecton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
to omit the attribute if the attribute is marked as optional. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to put things simply. But any advice are welcome 😅 |
||
|
||
```rust | ||
let maybe_id = Some("foobar"); | ||
|
||
html! { | ||
<div id?=maybe_id></div> | ||
<div id=maybe_id></div> | ||
} | ||
``` | ||
|
||
If the attribute is set to `None`, the attribute won't be set in the DOM. | ||
|
||
Please note that it is also valid to give only the value as properties behave | ||
like `Into<Option<T>>`: | ||
|
||
```rust | ||
let id = "foobar"; | ||
|
||
html! { | ||
<div id=id></div> | ||
} | ||
``` | ||
|
||
Comment on lines
+37
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the remark I added about the optional attributes. |
||
## Listeners | ||
|
||
Listener attributes need to be passed a `Callback` which is a wrapper around a closure. How you create your callback depends on how you wish your app to react to a listener event: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the entire section here. I added a note about
Into<Option<T>>
later on.