Comments (18)
There are three options I have in mind, hopefully we could support both:
style="width: ${prop}px"
style="width.bind: prop"
style.bind="someProperty"
Our current options properties for attached behaviors support these patterns and I thought it would be nice to have it work the same for style. We need special handling to make it happen though. I haven't looked into what it would take just yet.
If we do 3 then we should probably also do class.bind="someProperty"
as well.
from binding.
in # 3 (style.bind), the value of someProperty
is a string? something like 'color: #23432; margin-top: 25px;' or is it an object (like KO) or both?
same question for the class.bind scenario.
would it be possible to change # 2 to this: style.width.bind="someProperty"
or this style-width.bind="someProperty"
from binding.
I'm wondering if we could handle both scenarios. One way might be with a value converter (which we can make built in) that converts objects into strings, for example.
from binding.
another option for # 2- maybe we introduce the value converter :
argument syntax to attached behaviors?
<div style:background-color.bind="propertyName"></div>
from binding.
I'd like to not add more syntax if I can help it. One problem with this in particular is that it looks like a namespace. The second option is already implemented for attached behavior so if we can make the built-in style work the same, that would be my preference, for consistency sake.
from binding.
played around with this some- might need to change course:
app.html
<template>
<h1>Scenario #1</h1>
<div style="color: ${color}; background-color: ${backgroundColor}">
test
</div>
<h1>Scenario #2</h1>
<div style="color.bind: color; background-color.bind: backgroundColor">
test
</div>
<h1>Scenario #3</h1>
<div style.bind="style">
test
</div>
</template>
app.js
import {declarePropertyDependencies} from 'aurelia-framework';
export class App {
constructor() {
this.color = '#FF0040';
this.backgroundColor = '#610B21';
setInterval(() => {
var temp = this.color;
this.color = this.backgroundColor;
this.backgroundColor = temp;
}, 1000);
}
get style() {
return `color: ${this.color}; background-color: ${this.backgroundColor}`;
}
}
declarePropertyDependencies(App, 'style', ['color', 'backgroundColor']);
- A small change to the ElementObserver adds support for scenario 3 in all browsers.
- The same change adds support for scenario 1 in all browsers except Internet Explorer. IE seems to be strict about invalid css in the style attribute. In scenario 1, when TemplatingBindingLanguage.inspectAttribute is called, the attrValue argument is empty string. The DOM explorer also shows
style=""
. I suspect we'll encounter the same issue when adding support for scenario 2 if the binding expressions are non-trivial.
Does this mean we must go with a different attribute name? au-style
maybe? Or do we scale back this feature to only include scenario 3?
from binding.
That's disappointing. I wonder if there's any other way, via the DOM, to get at the raw style value. If not, we probably will need to add au-style
. It's not that big of a deal...but it rubs me the wrong way. I was really hoping to not bring in custom behaviors for normal binding scenarios. Can you do a little more research around style and see if there's any other way to get that value?
from binding.
sure
from binding.
still researching but here's some early findings (not promising):
original markup for $0
is:
<div style="color: ${color}; background-color: ${backgroundColor}">
scenario 1
</div>
strange the style panel shows some info- must be a way to get at this that I haven't tried
from binding.
What about $0.attributes.style
it seems to return the raw value here
edit well $0.attributes.style.value
to get the value I guess
from binding.
not for me, I get an empty string.
from binding.
Edit Nevermind just re-read everything and saw this was only for IE
from binding.
I'm voting for css="color: ${color}"
from binding.
@AshleyGrant , @PWKad and I were discussing this some more in the gitter.... here's a recap:
style.bind
All browsers support what we want to do with <input style.bind="someProperty">
. We're updating the ElementObserver
to assign the element's style.cssText
property. someProperty
might be a string, color: red; background-color: blue;
or it might be an object which we'd flatten into a css string.
interpolation style="color: ${someProperty}"
All browsers except Internet Explorer support this syntax. Internet Explorer "blanks out" the style attribute when it encounters invalid css. We couldn't find a way to get the original markup so we need to use a different attribute name. Several options have been proposed:
<input au-style="color: ${someProperty}">
<input css="color: ${someProperty}">
<input style.interpolate="color: ${someProperty}">
<input style.parse="color: ${someProperty}">
<input style.assign="color: ${someProperty}">
<input style.set="color: ${someProperty}">
There are pros and cons for each approach:
- The
au-style
andcss
approaches introduce a new attribute for assigningstyle
which will require us to document the app behavior when both acss
/au-style
attribute and a nativestyle
attribute are present on the same element. Not to mention we'll need to document thatcss
should be used instead ofstyle
when doing interpolation. - The
style.something
approaches introduce a new binding command which is only used for style attributes. What's nice about this is we think devs will assume that the behavior here is thestyle.something
attribute will overwrite the nativestyle
attribute and won't attempt to putstyle.something=...
andstyle=...
on the same element. - Both approaches require aurelia to log a warning about Internet Explorer incompatibility when someone puts an interpolation expression in the native
style
attribute.
from binding.
If I understand correctly, in IE (which is still the most common browser inside enterprises) the only option to bind styles is to set the full style
property? That's very annoying, especially for something as useful and common as style
(think about dynamic layouts or transforms, data visualizations that bind to the size or color or opacity, etc.).
@jdanyow suggestion to use style.background-color.bind='xx'
feels very natural and hardly "new syntax". After all backgroundColor
is a property of the style
object.
from binding.
Hi guys,
I have an element like the one below
innerHTML.bind="filler(col, item)"
I need to be able to bind the raw HTML returned. Example
this.renders["check"] = function(col, item){
return '<input type="inpute" value.two-way=`${hola}`/>';
};
How can I accomplish that?
Thanks.
from binding.
was this solved, I need to do 👍
< option repeat.for="colour of typeColours" css="color: #333333; background-color:${colour};">
for a multi coloured select drop down. It works in Chrome but not in IE.
I've tried various things from this issue post but nothing works.
Any help much appreciated.
Cheers!
Rob
from binding.
<div css="padding-left: ${depth * 20}px">...</div>
does not seem to work -- no style
attribute is emitted on the element at all. Suggestions?
from binding.
Related Issues (20)
- path expressions containing 'in' no longer working, 'in' treated as keyword HOT 3
- Issue with aurelia/binding typings HOT 12
- Issue with interpolation binding inside HTML `<option>` element HOT 2
- Checkbox event arguments in repeaters not binding correctly HOT 5
- @behel33 Thanks for creating the issue, I couldn't recreate the behavior you described, can you help fix this codesandbox https://codesandbox.io/s/x761qq5p3q HOT 1
- Infinite loop with 100+ observers HOT 17
- click.delegate bindings stop working HOT 14
- click.delegate firing for all clicks on firefox rather than just left click HOT 5
- Binding on role attribute not working in Firefox HOT 4
- Delegate event bubbling does not match native behavior in shadow dom
- Infinite loop in aurelia-bindingd.ts OverrideContext HOT 13
- parsing of template issue: ${moment().toISOString()} does not work HOT 1
- Parser Error: Invalid start of expression at column 0 in expression []
- Optimizing getter access HOT 1
- Matcher ignored within repeater HOT 7
- Delegate does not support shadow dom for Firefox
- getContextFor() doesn't handle a non-object bindingContext HOT 3
- Can we use/make attached/detached method inside aurelia custom element? HOT 3
- Binding checkboxes: custom matcher does not work when using repeat.for HOT 3
- SetterObserver keeps old value retained HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from binding.