Skip to content

Commit 7348ea1

Browse files
committed
Merge pull request #11889 from rwjblue/attributeBindings-for-id
[BUGFIX release] Fix `attributeBindings` for `id` attribute.
2 parents 86d63d4 + 712227c commit 7348ea1

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

packages/ember-views/lib/system/build-component-template.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ function normalizeComponentAttributes(component, isAngleBracket, attrs) {
139139
var attributeBindings = component.attributeBindings;
140140
var i, l;
141141

142+
if (attrs.id && getValue(attrs.id)) {
143+
// Do not allow binding to the `id`
144+
normalized.id = getValue(attrs.id);
145+
component.elementId = normalized.id;
146+
} else {
147+
normalized.id = component.elementId;
148+
}
149+
142150
if (attributeBindings) {
143151
for (i = 0, l = attributeBindings.length; i < l; i++) {
144152
var attr = attributeBindings[i];
@@ -178,14 +186,6 @@ function normalizeComponentAttributes(component, isAngleBracket, attrs) {
178186
}
179187
}
180188

181-
if (attrs.id && getValue(attrs.id)) {
182-
// Do not allow binding to the `id`
183-
normalized.id = getValue(attrs.id);
184-
component.elementId = normalized.id;
185-
} else {
186-
normalized.id = component.elementId;
187-
}
188-
189189
if (attrs.tagName) {
190190
component.tagName = attrs.tagName;
191191
}

packages/ember-views/tests/views/view/attribute_bindings_test.js

+11
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,14 @@ QUnit.test('role attribute is not included if not provided', function() {
466466

467467
ok(!view.element.hasAttribute('role'), 'role attribute is not present');
468468
});
469+
470+
QUnit.test('can set id initially via attributeBindings', function() {
471+
view = EmberView.create({
472+
attributeBindings: ['specialSauce:id'],
473+
specialSauce: 'special-sauces-id'
474+
});
475+
476+
appendView();
477+
478+
equal(view.$().attr('id'), 'special-sauces-id', 'id properly used from attributeBindings');
479+
});

0 commit comments

Comments
 (0)