Skip to content

Commit

Permalink
feat(attributes-to-props): check for overloaded boolean values
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
remarkablemark committed Jul 7, 2019
1 parent 17fbdfd commit 1151cfb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/attributes-to-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ function attributesToProps(attributes) {
// convert HTML attribute to React prop
property = HTMLDOMPropertyConfig[attributeName.toLowerCase()];
if (property) {
if (property.hasBooleanValue) {
props[property.propertyName] = true;
} else {
props[property.propertyName] = attributeValue;
}
props[property.propertyName] =
property.hasBooleanValue ||
(property.hasOverloadedBooleanValue && !attributeValue)
? true
: attributeValue;
continue;
}

Expand Down
20 changes: 20 additions & 0 deletions test/attributes-to-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ describe('attributesToProps', () => {
}
);
});

it('converts overloaded boolean attributes', () => {
assert.deepEqual(
attributesToProps({
download: ''
}),
{
download: true
}
);

assert.deepEqual(
attributesToProps({
download: 'filename'
}),
{
download: 'filename'
}
);
});
});

describe('SVG', () => {
Expand Down

0 comments on commit 1151cfb

Please sign in to comment.