Conversation
|
Visit the preview URL for this PR (updated for commit 6240128): https://yew-rs--pr3509-dyn-prop-v9qsw7el.web.app (expires Sun, 12 Apr 2026 02:00:32 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
|
My local setup told me nothing about which Rust version is used, wow... Fixing 1.64.0 compiler support shortly I guess, there is nothing special, just |
Size ComparisonDetails
✅ None of the examples has changed their size significantly. |
Benchmark - SSRYew MasterDetails
Pull RequestDetails
|
|
Uh sorry, will check what it fails on tomorrow |
|
Wow, I passed even the benchmark lol |
|
You need both passing and failing tests for it. You can copy a |
|
If there are any |
There was a problem hiding this comment.
Awesome! I need this. At the moment I'm building the component linearGradient manually and it's such a pain
#[function_component(LinearGradient)]
pub fn linear_gradient(
Props {
id,
gradient_transform,
children,
}: &Props,
) -> Html {
let mut vtag = yew::virtual_dom::VTag::new("linearGradient");
vtag.add_children(children.clone());
vtag.add_attribute("id", id.clone());
if let Some(x) = gradient_transform.clone() {
vtag.add_attribute("gradientTransform", x);
}
vtag.into()
}
Now with autoprops + dyn prop labels, I can simplify this code a lot
|
I tried to add following to the // property literal
_ = ::yew::html! { <span ~"hx-on:click"="alert('Clicked!')" /> };
_ = ::yew::html! { <span ~"hx-on:click"="alert('Clicked!')" ~"hx-on:click"="alert('Clicked!')" /> };
_ = ::yew::html! { <span ~{ "hx-on:click" }={ "alert('Clicked!')" } /> };
_ = ::yew::html! { <span ~{ "hx-on:click" }={ "alert('Clicked!')" } ~{ "hx-on:click" }={ "alert('Clicked!')" } /> };
// property expr
_ = ::yew::html! { <span ~{ dyn_prop() }={ "alert('Clicked!')" } /> };
_ = ::yew::html! { <span ~{ dyn_prop() }={ "alert('Clicked!')" } ~{ dyn_prop() }={ "alert('Clicked!')" } /> };Tests ( As I was trying to find out whether any tests would help me figure out how to test the feature, I performed a quick search on all tests, only to find out that nobody tested |
Either this is an outdated comment or you missed something, because there are Wasm tests that use |
Allows not only literals, e.g. "hx-on:click", but all expressions
Avoid temporary TokenStream allocation in ToTokens impls for PropLabel and Key by delegating directly. Fix Display requirement on PropLabel in component.rs after rebase brought in is_none_expr. Remove resolved FIXME on IndexMap filter_map. Update dyn-prop-fail.stderr for Rust 1.84.
Add "Dynamic attribute names" section to elements.mdx and a brief mention with link in introduction.mdx. Includes translations for ja, zh-Hans, and zh-Hant locales.
Madoshakalaka
left a comment
There was a problem hiding this comment.
Thanks for the PR. I rebased and addressed Shrimp's reviews. Added docs to the website too.
Description
Partially implements features from discussion #3477. This PR adds Dynamic Prop Labels, so that anyone can write their favorite attributes like HTMX's
hx-on:click:It works by using new
PropLabelenum everywhere, which can be either aStaticHtmlDashedNamelike before, orDynamicExpr. When parsing, if it meets=token after the expression group, it will read a value following it instead of assuming that it is shorthand syntax.Checklist