Skip to content

Commit 8502f08

Browse files
committed
[Bugfix Beta] Fix attrs in className and attribute bindings
1 parent 26cc7d2 commit 8502f08

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

packages/ember-glimmer/lib/utils/bindings.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ function referenceForKey(component, key) {
1414
}
1515

1616
function referenceForParts(component, parts) {
17+
let isAttrs = parts[0] === 'attrs';
18+
19+
// TODO deprecate this
20+
if (isAttrs) {
21+
parts.shift();
22+
23+
if (parts.length === 1) {
24+
return referenceForKey(component, parts[0]);
25+
}
26+
}
27+
1728
return referenceFromParts(component[ROOT_REF], parts);
1829
}
1930

packages/ember-glimmer/tests/integration/components/attribute-bindings-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,37 @@ moduleFor('Attribute bindings integration', class extends RenderingTest {
3434
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': 'foo', 'data-bar': 'bar' }, content: 'hello' });
3535
}
3636

37+
['@test it can have attribute bindings with attrs']() {
38+
let FooBarComponent = Component.extend({
39+
attributeBindings: ['attrs.foo:data-foo', 'attrs.baz.bar:data-bar']
40+
});
41+
42+
this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' });
43+
44+
this.render('{{foo-bar foo=model.foo baz=model.baz}}', {
45+
model: { foo: undefined, baz: { bar: 'bar' } }
46+
});
47+
48+
this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'data-bar': 'bar' } });
49+
50+
this.runTask(() => this.rerender());
51+
52+
this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'data-bar': 'bar' } });
53+
54+
this.runTask(() => {
55+
set(this.context, 'model.foo', 'foo');
56+
set(this.context, 'model.baz.bar', undefined);
57+
});
58+
59+
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': 'foo' }, content: 'hello' });
60+
61+
this.runTask(() => set(this.context, 'model', {
62+
foo: undefined, baz: { bar: 'bar' }
63+
}));
64+
65+
this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'data-bar': 'bar' } });
66+
}
67+
3768
['@test it can have attribute bindings with a nested path']() {
3869
let FooBarComponent = Component.extend({
3970
attributeBindings: ['foo.bar:data-foo-bar']

packages/ember-glimmer/tests/integration/components/class-bindings-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,37 @@ moduleFor('ClassNameBindings integration', class extends RenderingTest {
4444
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': classes('ember-view foo enabled sad') }, content: 'hello' });
4545
}
4646

47+
['@test attrs in classNameBindings']() {
48+
let FooBarComponent = Component.extend({
49+
classNameBindings: ['attrs.joker:purple:green', 'attrs.batman.robin:black:red']
50+
});
51+
52+
this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' });
53+
54+
this.render('{{foo-bar joker=model.wat batman=model.super}}', {
55+
model: { wat: false, super: { robin: true } }
56+
});
57+
58+
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': classes('ember-view green black') }, content: 'hello' });
59+
60+
this.runTask(() => this.rerender());
61+
62+
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': classes('ember-view green black') }, content: 'hello' });
63+
64+
this.runTask(() => {
65+
set(this.context, 'model.wat', true);
66+
set(this.context, 'model.super.robin', false);
67+
});
68+
69+
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': classes('ember-view purple red') }, content: 'hello' });
70+
71+
this.runTask(() => set(this.context, 'model', {
72+
wat: false, super: { robin: true }
73+
}));
74+
75+
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': classes('ember-view green black') }, content: 'hello' });
76+
}
77+
4778
['@test it can have class name bindings in the template']() {
4879
this.registerComponent('foo-bar', { template: 'hello' });
4980

0 commit comments

Comments
 (0)