@@ -9,8 +9,13 @@ import { PRESERVE_CUSTOM_ATTRIBUTES, setStyleProp } from './utilities';
99
1010// https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components
1111// https://developer.mozilla.org/docs/Web/HTML/Attributes
12- const UNCONTROLLED_COMPONENT_ATTRIBUTES = [ 'checked' , 'value' ] ;
13- const UNCONTROLLED_COMPONENT_NAMES = [ 'input' , 'select' , 'textarea' ] ;
12+ const UNCONTROLLED_COMPONENT_ATTRIBUTES = [ 'checked' , 'value' ] as const ;
13+ const UNCONTROLLED_COMPONENT_NAMES = [ 'input' , 'select' , 'textarea' ] as const ;
14+
15+ type UncontrolledComponentAttributes =
16+ ( typeof UNCONTROLLED_COMPONENT_ATTRIBUTES ) [ number ] ;
17+
18+ type UncontrolledComponentNames = ( typeof UNCONTROLLED_COMPONENT_NAMES ) [ number ] ;
1419
1520const valueOnlyInputs = {
1621 reset : true ,
@@ -63,8 +68,12 @@ export default function attributesToProps(
6368
6469 // convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
6570 if (
66- UNCONTROLLED_COMPONENT_ATTRIBUTES . indexOf ( propName ) !== - 1 &&
67- UNCONTROLLED_COMPONENT_NAMES . indexOf ( nodeName ! ) !== - 1 &&
71+ UNCONTROLLED_COMPONENT_ATTRIBUTES . indexOf (
72+ propName as UncontrolledComponentAttributes ,
73+ ) !== - 1 &&
74+ UNCONTROLLED_COMPONENT_NAMES . indexOf (
75+ nodeName ! as UncontrolledComponentNames ,
76+ ) !== - 1 &&
6877 ! isInputValueOnly
6978 ) {
7079 propName = getPropName ( 'default' + attributeNameLowerCased ) ;
0 commit comments