Skip to content

Commit 1151cfb

Browse files
feat(attributes-to-props): check for overloaded boolean values
For HTML DOM attributes that can be either boolean or string, make sure to convert the value correctly for React. Add test to confirm `download` attribute is properly converted.
1 parent 17fbdfd commit 1151cfb

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/attributes-to-props.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ function attributesToProps(attributes) {
3333
// convert HTML attribute to React prop
3434
property = HTMLDOMPropertyConfig[attributeName.toLowerCase()];
3535
if (property) {
36-
if (property.hasBooleanValue) {
37-
props[property.propertyName] = true;
38-
} else {
39-
props[property.propertyName] = attributeValue;
40-
}
36+
props[property.propertyName] =
37+
property.hasBooleanValue ||
38+
(property.hasOverloadedBooleanValue && !attributeValue)
39+
? true
40+
: attributeValue;
4141
continue;
4242
}
4343

test/attributes-to-props.js

+20
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ describe('attributesToProps', () => {
109109
}
110110
);
111111
});
112+
113+
it('converts overloaded boolean attributes', () => {
114+
assert.deepEqual(
115+
attributesToProps({
116+
download: ''
117+
}),
118+
{
119+
download: true
120+
}
121+
);
122+
123+
assert.deepEqual(
124+
attributesToProps({
125+
download: 'filename'
126+
}),
127+
{
128+
download: 'filename'
129+
}
130+
);
131+
});
112132
});
113133

114134
describe('SVG', () => {

0 commit comments

Comments
 (0)