Skip to content

Commit

Permalink
fix(html): handle global boolean attributes without value
Browse files Browse the repository at this point in the history
  • Loading branch information
joneff committed Oct 5, 2021
1 parent dac8c87 commit 28bf2d2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/html/lib/jsx-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,39 @@ const attrMap = {
fillmode: 'fillMode'
};

const booleanAttr = new Set([
'hidden',

'hover',
'focus',
'active',
'disabled',

'selected',

'checked',
'indeterminate',

'aria'
]);

function attrToProps( element ) {
let attributes = element.attributes;
let props = {};

Array.from(attributes).forEach((attrObj) => {
let attrName = attrObj.name;
let attrValue = attrObj.value;

if (attrMap[attrName]) {
attrName = attrMap[attrName];
}

props[ attrName ] = attrObj.value;
if (booleanAttr.has(attrName) && attrValue === '') {
props[ attrName ] = true;
} else {
props[ attrName ] = attrValue;
}
});

return props;
Expand Down

0 comments on commit 28bf2d2

Please sign in to comment.