Skip to content

Commit e478a44

Browse files
fix(parser): fix boolean attributes parsing
1 parent 29084cf commit e478a44

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/attributes-to-props.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ var styleToObject = require('style-to-object');
99
var config = propertyConfig.config;
1010
var isCustomAttribute = propertyConfig.HTMLDOMPropertyConfig.isCustomAttribute;
1111

12+
var DOMProperty = require('react-dom-core/lib/DOMProperty');
13+
DOMProperty.injection.injectDOMPropertyConfig(propertyConfig.HTMLDOMPropertyConfig);
14+
1215
/**
1316
* Make attributes compatible with React props.
1417
*
@@ -34,7 +37,11 @@ function attributesToProps(attributes) {
3437
// make HTML DOM attribute/property consistent with React attribute/property
3538
reactProperty = config.html[propertyName.toLowerCase()];
3639
if (reactProperty) {
37-
props[reactProperty] = propertyValue;
40+
if (DOMProperty.properties.hasOwnProperty(reactProperty) && DOMProperty.properties[reactProperty].hasBooleanValue) {
41+
props[reactProperty] = true;
42+
} else {
43+
props[reactProperty] = propertyValue;
44+
}
3845
continue;
3946
}
4047

test/attributes-to-props.js

+20
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ describe('attributes to props helper', function() {
102102
);
103103
});
104104

105+
it('converts bool properties', function() {
106+
assert.deepEqual(
107+
attributesToProps({
108+
readonly: ''
109+
}),
110+
{
111+
readOnly: true
112+
}
113+
);
114+
115+
assert.deepEqual(
116+
attributesToProps({
117+
disabled: 'disabled'
118+
}),
119+
{
120+
disabled: true
121+
}
122+
);
123+
});
124+
105125
});
106126

107127
/**

0 commit comments

Comments
 (0)