88 */
99
1010import * as React from 'react' ;
11- import { Fragment , useRef } from 'react' ;
11+ import { Fragment } from 'react' ;
1212import styles from './EditableValue.css' ;
1313import { useEditableValue } from '../hooks' ;
1414
@@ -27,7 +27,6 @@ export default function EditableValue({
2727 path,
2828 value,
2929} : EditableValueProps ) {
30- const inputRef = useRef < HTMLInputElement | null > ( null ) ;
3130 const [ state , dispatch ] = useEditableValue ( value ) ;
3231 const { editableValue, hasPendingChanges, isValid, parsedValue} = state ;
3332
@@ -50,6 +49,12 @@ export default function EditableValue({
5049 editableValue : target . checked ,
5150 externalValue : value ,
5251 } ) ;
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.
5358 overrideValueFn ( path , target . checked ) ;
5459 } ;
5560
@@ -93,7 +98,6 @@ export default function EditableValue({
9398 onChange = { handleChange }
9499 onKeyDown = { handleKeyDown }
95100 placeholder = { placeholder }
96- ref = { inputRef }
97101 type = "text"
98102 value = { editableValue }
99103 />
0 commit comments