8
8
*/
9
9
10
10
import * as React from 'react' ;
11
- import { Fragment , useRef } from 'react' ;
11
+ import { Fragment } from 'react' ;
12
12
import styles from './EditableValue.css' ;
13
13
import { useEditableValue } from '../hooks' ;
14
14
@@ -27,7 +27,6 @@ export default function EditableValue({
27
27
path,
28
28
value,
29
29
} : EditableValueProps ) {
30
- const inputRef = useRef < HTMLInputElement | null > ( null ) ;
31
30
const [ state , dispatch ] = useEditableValue ( value ) ;
32
31
const { editableValue, hasPendingChanges, isValid, parsedValue} = state ;
33
32
@@ -50,6 +49,12 @@ export default function EditableValue({
50
49
editableValue : target . checked ,
51
50
externalValue : value ,
52
51
} ) ;
52
+
53
+ // Unlike <input type="text"> which has both an onChange and an onBlur,
54
+ // <input type="checkbox"> updates state *and* applies changes in a single event.
55
+ // So we read from target.checked rather than parsedValue (which has not yet updated).
56
+ // We also don't check isValid (because that hasn't changed yet either);
57
+ // we don't need to check it anyway, since target.checked is always a boolean.
53
58
overrideValueFn ( path , target . checked ) ;
54
59
} ;
55
60
@@ -93,7 +98,6 @@ export default function EditableValue({
93
98
onChange = { handleChange }
94
99
onKeyDown = { handleKeyDown }
95
100
placeholder = { placeholder }
96
- ref = { inputRef }
97
101
type = "text"
98
102
value = { editableValue }
99
103
/>
0 commit comments