Skip to content

Commit badcc37

Browse files
committed
Merge pull request #5 from mjj2000/fix-boolean-attribute
[fix] match boolean attributes that contain upper case characters
2 parents 86d876c + 1edc2d0 commit badcc37

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/utils/HtmlAttributesToReact.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const getParsedAttributeValue = function(attribute, value) {
1212

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

test/unit/utils/HtmlAttributesToReact.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ describe('Testing `utils/HtmlAttributesToReact`', () => {
2222
'UPPER-CASE-TEST-ATTRIBUTE': 'upperTestAttribute',
2323
// boolean attributes
2424
disabled: '',
25-
checked: ''
25+
checked: '',
26+
autoplay: ''
2627
};
2728

2829
const expectedReactAttributes = {
2930
className: 'testClass',
3031
htmlFor: 'testFor',
3132
minLength: 1,
3233
acceptCharset: 'testAcceptCharset',
33-
formNoValidate: 'testFormNoValidate',
34+
formNoValidate: 'formNoValidate',
3435
label: 'testLabel',
3536
'data-test': 'test',
3637
'aria-role': 'role',
3738
testattribute: 'testAttribute',
3839
'upper-case-test-attribute': 'upperTestAttribute',
3940
disabled: 'disabled',
40-
checked: 'checked'
41+
checked: 'checked',
42+
autoPlay: 'autoPlay'
4143
};
4244

4345
expect(HtmlAttributesToReact(htmlAttributes)).toEqual(expectedReactAttributes);

0 commit comments

Comments
 (0)