@samitouri / QOS-React-2 / commits / eb4e44a3c9

Fixed consistency of behavior boolean properties

Toru Kobayashi committed Aug 5, 2015 at 18:57 UTC eb4e44a3c94f960c25edc79ff17e4682dd6312bb
2 files changed +12
src/renderers/dom/shared/DOMPropertyOperations.js
+3
@@ -173,6 +173,9 @@ var DOMPropertyOperations = {
173 // ('' + value) makes it output the correct toString()-value.
174 if (namespace) {
175 node.setAttributeNS(namespace, attributeName, '' + value);
176 + } else if (propertyInfo.hasBooleanValue ||
177 + (propertyInfo.hasOverloadedBooleanValue && value === true)) {
178 + node.setAttribute(attributeName, '');
179 } else {
180 node.setAttribute(attributeName, '' + value);
181 }
src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js
+9
@@ -224,6 +224,15 @@ describe('DOMPropertyOperations', function() {
224 .toEqual(['http://www.w3.org/1999/xlink', 'xlink:href', 'about:blank']);
225 });
226
227 + it('should set values as boolean properties', function() {
228 + DOMPropertyOperations.setValueForProperty(stubNode, 'disabled', 'disabled');
229 + expect(stubNode.getAttribute('disabled')).toBe('');
230 + DOMPropertyOperations.setValueForProperty(stubNode, 'disabled', true);
231 + expect(stubNode.getAttribute('disabled')).toBe('');
232 + DOMPropertyOperations.setValueForProperty(stubNode, 'disabled', false);
233 + expect(stubNode.getAttribute('disabled')).toBe(null);
234 + });
235 +
236 it('should convert attribute values to string first', function() {
237 // Browsers default to this behavior, but some test environments do not.
238 // This ensures that we have consistent behavior.