mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Remove custom attrs properly when setting to null
I don't think this particular codepath was exercised at all (because all the callers call deleteValueForProperty) but this fixes a bug here nonetheless.
This commit is contained in:
@@ -136,7 +136,7 @@ var DOMPropertyOperations = {
|
||||
}
|
||||
} else if (DOMProperty.isCustomAttribute(name)) {
|
||||
if (value == null) {
|
||||
node.removeAttribute(DOMProperty.getAttributeName[name]);
|
||||
node.removeAttribute(name);
|
||||
} else {
|
||||
node.setAttribute(name, '' + value);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user