Skip to content

Commit

Permalink
fix matching boolean attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mjj2000 committed May 7, 2016
1 parent 86d876c commit 1edc2d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/utils/HtmlAttributesToReact.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const getParsedAttributeValue = function(attribute, value) {

// if the attribute if a boolean then it's value should be the same as it's name
// e.g. disabled="disabled"
if (BooleanAttributes.indexOf(attribute) >= 0) {
let lowerBooleanAttributes = BooleanAttributes.map(attr => attr.toLowerCase());
if (lowerBooleanAttributes.indexOf(attribute.toLowerCase()) >= 0) {
value = attribute;
}

Expand Down
8 changes: 5 additions & 3 deletions test/unit/utils/HtmlAttributesToReact.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,24 @@ describe('Testing `utils/HtmlAttributesToReact`', () => {
'UPPER-CASE-TEST-ATTRIBUTE': 'upperTestAttribute',
// boolean attributes
disabled: '',
checked: ''
checked: '',
autoplay: ''
};

const expectedReactAttributes = {
className: 'testClass',
htmlFor: 'testFor',
minLength: 1,
acceptCharset: 'testAcceptCharset',
formNoValidate: 'testFormNoValidate',
formNoValidate: 'formNoValidate',
label: 'testLabel',
'data-test': 'test',
'aria-role': 'role',
testattribute: 'testAttribute',
'upper-case-test-attribute': 'upperTestAttribute',
disabled: 'disabled',
checked: 'checked'
checked: 'checked',
autoPlay: 'autoPlay'
};

expect(HtmlAttributesToReact(htmlAttributes)).toEqual(expectedReactAttributes);
Expand Down

0 comments on commit 1edc2d0

Please sign in to comment.