-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
7d330aa
start
siku2 f80566e
update examples
siku2 198567a
optional attributes for elements
siku2 e48605e
update macro tests
siku2 0ed35ff
update yew-stdweb todomvc example
siku2 5b7ee05
remove quote spanned
siku2 f6571e1
remove transformer trait
siku2 f8adf9b
first draft for unified prop handling
siku2 815147b
update examples
siku2 ec14013
update optional-attrs
siku2 692000a
don't even remember to be honest
siku2 907f05a
update optional-attrs branch
siku2 f2e6d99
Update optional-attrs
siku2 0535bdc
remove implicit cloning from strings
siku2 8de3926
update examples and docs
siku2 14a237a
update stdweb examples
siku2 110f789
Merge branch 'v0.18' into optional-attrs
jstarry 57f6ad1
Proper optional attribute for Option<T>
cecton f062f65
rustfmt
cecton 63d4e0d
Update test stderr (file moved)
cecton d9c9d52
Fix issues in `WebSocketTask` during connection (#1783) (#1785)
rhymu8354 dacafc6
Fix issues in `WebSocketTask` during connection (#1783) (#1785)
rhymu8354 b819ce6
Fix issues in `WebSocketTask` during connection (#1783) (#1785)
rhymu8354 3c36f3a
Fix fetch test for same-origin referrer URL (#1788)
rhymu8354 095d5d8
Fixing issue with integration test
cecton 8e4d246
Fix previous commit
cecton 3891794
Fix int test...
cecton 3fd536c
Disable tests for stdweb
cecton 8089f06
hmmhmm
cecton 637136a
hmmhmm
cecton 707c1e7
Be more specific to detect an Option
cecton d1b9f76
Field became not required
cecton b317330
Clippy
cecton 45d63a5
Oops this is not public API, we can fix it
cecton 3ee805e
Update documentation
cecton 5f98c06
Revert probable temporary change
cecton 8037e78
Solve some TODOs
cecton dfe7ccb
Clippy fix
cecton e488e99
Fix some doc
cecton af93a08
Update packages/yew-macro/src/derive_props/field.rs
cecton 9728825
Update Rust version for macro tests to 1.51 & enable const generics t…
ranile 390abdb
Update docs/concepts/html/elements.md
cecton 004ef9a
Clippy stuff
cecton 78a3129
Update test stderr for rustc 1.51
cecton ac09c97
More fix for 1.51.0
cecton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 us | ||
to omit the attribute if the attribute is marked as optional. | ||
|
||
```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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.