-
-
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
yew-macro: Handling of boolean properties #745
Comments
These both sound like great features, would gladly review PRs to fix them! Could you please split this issue into two? One for boolean handling and one for Option conversion? |
Alright, I'll do that now. I actually came across a similar situation to what you described in #756 - I have something like: let placeholder = if something { "something" } else { "something else" };
html! {
<input type="text" /* ... */ placeholder=placeholder />
} Being able to omit the |
Option<T>
and boolean properties
Missing label:
|
Hi! I am still pretty junior, but I am interested to work on this if it is something that is still wanted? I see that something similar will be done with #769 with the syntax there potentially colliding for the syntax here? Also after looking at the code I see that the lib doesn't "know" what type a prop is till the to_tokens call in the HtmlComponent struct (I could be wrong in this). While I could set the value to true automatically and then check over there if it is the correct type, I don't know if this will result in a well-understandable error in case the type of the prop isn't a bool. |
@Baev1 thanks for taking a look, you're totally right about that. I think we could only have this special handling for boolean html elements: yew/crates/macro/src/html_tree/html_tag/tag_attributes.rs Lines 27 to 49 in 22904eb
Even then, it's probably not so useful because it's much easier to enable/disable these types of attributes using a dynamic bool. I think it's safe to close this, so I'll do so. @Baev1 are you specifically interested in helping with the macro or would you be interested in helping on other issues? We can discuss in the gitter room if you want! |
Description
I'm submitting a feature request (I intend to work on this myself if I can find the time).
bool
defaults tofalse
, the property being missing already impliesfalse
, which is great. However, I'd really like it to work the other way around too: If a bool property is present, it should implytrue
(meaning I can write<MyComp myprop />
instead of<MyComp myprop=true />
).The text was updated successfully, but these errors were encountered: