@@ -9,8 +9,13 @@ import { PRESERVE_CUSTOM_ATTRIBUTES, setStyleProp } from './utilities';
9
9
10
10
// https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components
11
11
// 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 ] ;
14
19
15
20
const valueOnlyInputs = {
16
21
reset : true ,
@@ -63,8 +68,12 @@ export default function attributesToProps(
63
68
64
69
// convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
65
70
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 &&
68
77
! isInputValueOnly
69
78
) {
70
79
propName = getPropName ( 'default' + attributeNameLowerCased ) ;
0 commit comments