8
8
*/
9
9
10
10
import React , { Fragment , useRef } from 'react' ;
11
- import Button from '../Button' ;
12
- import ButtonIcon from '../ButtonIcon' ;
13
11
import styles from './EditableValue.css' ;
14
12
import { useEditableValue } from '../hooks' ;
15
13
@@ -51,9 +49,7 @@ export default function EditableValue({
51
49
52
50
switch ( event . key ) {
53
51
case 'Enter' :
54
- if ( isValid && hasPendingChanges ) {
55
- overrideValueFn ( path , parsedValue ) ;
56
- }
52
+ applyChanges ( ) ;
57
53
break ;
58
54
case 'Escape' :
59
55
reset ( ) ;
@@ -63,6 +59,12 @@ export default function EditableValue({
63
59
}
64
60
} ;
65
61
62
+ const applyChanges = ( ) => {
63
+ if ( isValid && hasPendingChanges ) {
64
+ overrideValueFn ( path , parsedValue ) ;
65
+ }
66
+ } ;
67
+
66
68
let placeholder = '' ;
67
69
if ( editableValue === undefined ) {
68
70
placeholder = '(undefined)' ;
@@ -75,21 +77,14 @@ export default function EditableValue({
75
77
< input
76
78
autoComplete = "new-password"
77
79
className = { `${ isValid ? styles . Input : styles . Invalid } ${ className } ` }
80
+ onBlur = { applyChanges }
78
81
onChange = { handleChange }
79
82
onKeyDown = { handleKeyDown }
80
83
placeholder = { placeholder }
81
84
ref = { inputRef }
82
85
type = "text"
83
86
value = { editableValue }
84
87
/>
85
- { hasPendingChanges && (
86
- < Button
87
- className = { styles . ResetButton }
88
- onClick = { reset }
89
- title = "Reset value" >
90
- < ButtonIcon type = "undo" />
91
- </ Button >
92
- ) }
93
88
</ Fragment >
94
89
) ;
95
90
}
0 commit comments