aurelia / templating-binding

An implementation of the templating engine's Binding Language abstraction which uses a pluggable command syntax.
MIT License
32 stars 26 forks source link

css-attribute without template does not translate to style-attribute #100

Closed vuorinem closed 6 years ago

vuorinem commented 7 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: Css attribute in template <div css="border: 1px solid red"></div> is not translated by Aurelia. This works fine: <div css="border: 1px solid red; ${anything}">.

See https://gist.run/?id=1bca105623d3c88400738985d008fc2e

Expected/desired behavior:

jdanyow commented 7 years ago

@EisenbergEffect this issue keeps coming up, there's (understandable) confusion about when to use css vs style. Currently, the content of a css attribute is applied to the element's style when the css attribute has a binding command or contains interpolation. This is because the code that maps css to style is in the ObserverLocator.

To resolve this, I think we need to map css attributes to style at a higher level. The contents of the css attribute could moved into the style attribute if the following criteria are met:

  1. The css attribute is not using a binding command (eg css.bind / css.one-time / etc)
  2. The css attribute does not contain interpolation (eg css="${foo} bar baz")

If the criteria are not met we'd create a style attribute binding.

This seems like the kind of logic that belongs in templating-binding but it will be difficult to add there without API changes. It would be pretty easy to add this logic in templating's ViewCompiler however.

What do you think?

EisenbergEffect commented 7 years ago

I definitely think we need to address this issue. The templating-binding repo is probably the correct place to put it. My question is, could we do that without introducing a breaking change? If not, could we put it into the templating repo without making a breaking change, but then plan to move it elsewhere whenever we get around to 2.0?

Let me know what you think.

Alexander-Taran commented 6 years ago

We can add a note to docs with this pr. There is a paragraph changed and example added. Needs review. I'm not sure I got it right.

EisenbergEffect commented 6 years ago

Looks good. Merged.