11var reactProperty = require ( 'react-property' ) ;
22var utilities = require ( './utilities' ) ;
33
4+ // https://reactjs.org/docs/uncontrolled-components.html
5+ // https://developer.mozilla.org/docs/Web/HTML/Attributes
6+ var UNCONTROLLED_COMPONENT_ATTRIBUTES = [ 'checked' , 'value' ] ;
7+ var UNCONTROLLED_COMPONENT_NAMES = [ 'input' , 'select' , 'textarea' ] ;
8+
9+ var VALUE_ONLY_INPUTS = {
10+ reset : true ,
11+ submit : true
12+ } ;
13+
414/**
515 * Converts HTML/SVG DOM attributes to React props.
616 *
@@ -11,18 +21,13 @@ var utilities = require('./utilities');
1121module . exports = function attributesToProps ( attributes , nodeName ) {
1222 attributes = attributes || { } ;
1323
14- var valueOnlyInputs = {
15- reset : true ,
16- submit : true
17- } ;
18-
1924 var attributeName ;
2025 var attributeNameLowerCased ;
2126 var attributeValue ;
2227 var propName ;
2328 var propertyInfo ;
2429 var props = { } ;
25- var inputIsValueOnly = attributes . type && valueOnlyInputs [ attributes . type ] ;
30+ var inputIsValueOnly = attributes . type && VALUE_ONLY_INPUTS [ attributes . type ] ;
2631
2732 for ( attributeName in attributes ) {
2833 attributeValue = attributes [ attributeName ] ;
@@ -41,10 +46,9 @@ module.exports = function attributesToProps(attributes, nodeName) {
4146 propertyInfo = reactProperty . getPropertyInfo ( propName ) ;
4247
4348 // convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
44- // https://reactjs.org/docs/uncontrolled-components.html
4549 if (
46- ( propName === 'checked' || propName === 'value' ) &&
47- nodeName !== 'option' &&
50+ UNCONTROLLED_COMPONENT_ATTRIBUTES . indexOf ( propName ) !== - 1 &&
51+ UNCONTROLLED_COMPONENT_NAMES . indexOf ( nodeName ) !== - 1 &&
4852 ! inputIsValueOnly
4953 ) {
5054 propName = getPropName ( 'default' + attributeNameLowerCased ) ;
0 commit comments