Skip to content

Commit

Permalink
Merge pull request facebook#1190 from spicyj/custom-set-null
Browse files Browse the repository at this point in the history
Remove custom attrs properly when setting to null
  • Loading branch information
chenglou committed Apr 12, 2014
2 parents b067556 + c3cfcf0 commit f4f6b05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/browser/ui/dom/DOMPropertyOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ var DOMPropertyOperations = {
}
} else if (DOMProperty.isCustomAttribute(name)) {
if (value == null) {
node.removeAttribute(DOMProperty.getAttributeName[name]);
node.removeAttribute(name);
} else {
node.setAttribute(name, '' + value);
}
Expand Down
15 changes: 15 additions & 0 deletions src/browser/ui/dom/__tests__/DOMPropertyOperations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ describe('DOMPropertyOperations', function() {
expect(stubNode.hasAttribute('allowFullScreen')).toBe(false);
});

it('should remove when setting custom attr to null', function() {
DOMPropertyOperations.setValueForProperty(
stubNode,
'data-foo',
'bar'
);
expect(stubNode.hasAttribute('data-foo')).toBe(true);
DOMPropertyOperations.setValueForProperty(
stubNode,
'data-foo',
null
);
expect(stubNode.hasAttribute('data-foo')).toBe(false);
});

it('should use mutation method where applicable', function() {
var foobarSetter = mocks.getMockFunction();
// inject foobar DOM property
Expand Down

0 comments on commit f4f6b05

Please sign in to comment.