leptos icon indicating copy to clipboard operation
leptos copied to clipboard

0.7 attribute values

Open blorbb opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe. How attribute values work is slightly inconsistent and rust-analyzer support isn't the best

Describe the solution you'd like This was discussed briefly on discord:

1. Require braces for attribute values except for str/num/bool literals.

Right now you can do attr=arbitrary.expression() + thing - but this requires that the expression after the = is valid - if you write something like arbitrary., the macro won't expand and you don't get any autocomplete suggestions after the ..

This change would require any non-literal expressions to be wrapped in braces, like attr={arbitrary.expression() + thing}. This makes it easier to parse (just take everything inside the {}), providing r-a support even in incomplete expressions.

2. More consistent value shorthands

On HTML attributes, the attribute checked is equivalent to checked=true, while on leptos components, it is checked={checked}. Make this consistent by making checked always equivalent to checked=true, and {checked} equivalent to checked={checked}.

Both of these changes are also what other frameworks like Svelte does.

Describe alternatives you've considered

staying with the current macro.

Additional context

My own view macro leptos-mview implements these requirements, and does have significantly better r-a support. Feel free to steal parts of my implementation for this change.

blorbb avatar Jan 18 '24 01:01 blorbb

I like this!

jquesada2016 avatar Jan 27 '24 13:01 jquesada2016

Yes, I would love a stricter/more consistent view macro aswell

jonahlund avatar Jan 31 '24 18:01 jonahlund

I could see this in 0.7 if someone wants to PR it and we can get a migration aid.

benwis avatar Jul 09 '24 16:07 benwis

ill have a go at implementing this

blorbb avatar Jul 09 '24 23:07 blorbb