Skip to content

Commit

Permalink
Avoids adding "elementClasses" twice
Browse files Browse the repository at this point in the history
Components may add elementClasses themselves for some reason (like progressive enhancement for Soy). In this case we should avoid adding it again, or the classes will show up twice in each element.
  • Loading branch information
mairatma committed Aug 12, 2016
1 parent 62e6c9c commit b0b8798
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class IncrementalDomRenderer extends ComponentRenderer {
*/
addElementClasses_(elementClasses, args) {
for (var i = 3; i < args.length; i += 2) {
if (args[i] === 'class') {
if (args[i] === 'class' && args[i + 1].indexOf(elementClasses) === -1) {
args[i + 1] += ' ' + elementClasses;
return;
}
Expand Down
14 changes: 14 additions & 0 deletions packages/metal-incremental-dom/test/IncrementalDomRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ describe('IncrementalDomRenderer', function() {
});
});

it('should not cause css classes to be added twice due to "elementClasses"', function() {
class TestComponent extends Component {
render() {
IncDom.elementVoid('div', null, null, 'class', this.elementClasses);
}
}
TestComponent.RENDERER = IncrementalDomRenderer;

component = new TestComponent({
elementClasses: 'test'
});
assert.strictEqual('test', component.element.getAttribute('class'));
});

describe('Existing Content', function() {
it('should not change existing content if the same that would be rendered', function() {
class TestComponent extends Component {
Expand Down

0 comments on commit b0b8798

Please sign in to comment.