@@ -139,7 +139,10 @@ export const BooleanValue: React.FC<InputProps & { value: boolean }> = ({
139139} ) => {
140140 const { getStyles } = useTheme ( )
141141
142- useKeyboardListener ( isEditing , handleEdit , handleCancel )
142+ const handleKeyPress = ( e : React . KeyboardEvent ) => {
143+ if ( e . key === 'Enter' ) handleEdit ( )
144+ else if ( e . key === 'Escape' ) handleCancel ( )
145+ }
143146
144147 return isEditing ? (
145148 < input
@@ -148,6 +151,8 @@ export const BooleanValue: React.FC<InputProps & { value: boolean }> = ({
148151 name = { toPathString ( path ) }
149152 checked = { value }
150153 onChange = { ( ) => setValue ( ! value ) }
154+ onKeyDown = { handleKeyPress }
155+ autoFocus
151156 />
152157 ) : (
153158 < span
@@ -170,53 +175,6 @@ export const NullValue: React.FC<InputProps> = ({
170175} ) => {
171176 const { getStyles } = useTheme ( )
172177
173- useKeyboardListener ( isEditing , handleEdit , handleCancel )
174-
175- return (
176- < div
177- onDoubleClick = { ( ) => setIsEditing ( true ) }
178- className = "jer-value-null"
179- style = { getStyles ( 'null' , nodeData ) }
180- >
181- { String ( value ) }
182- </ div >
183- )
184- }
185-
186- export const ObjectValue : React . FC < InputProps > = ( {
187- value,
188- translate,
189- isEditing,
190- handleEdit,
191- handleCancel,
192- nodeData,
193- } ) => {
194- useKeyboardListener ( isEditing , handleEdit , handleCancel )
195-
196- return (
197- < span className = "jer-value-object" > { `{${ translate ( 'DEFAULT_NEW_KEY' , nodeData ) } : "${ String (
198- value
199- ) } " }`} </ span >
200- )
201- }
202-
203- export const ArrayValue : React . FC < InputProps > = ( {
204- value,
205- isEditing,
206- handleEdit,
207- handleCancel,
208- } ) => {
209- useKeyboardListener ( isEditing , handleEdit , handleCancel )
210-
211- return < span className = "jer-value-array" > { `[${ value === null ? '' : String ( value ) } ]` } </ span >
212- }
213-
214- // Used for inputs that don't naturally register keyboard events
215- const useKeyboardListener = (
216- isEditing : boolean ,
217- handleEdit : ( ) => void ,
218- handleCancel : ( ) => void
219- ) => {
220178 useEffect ( ( ) => {
221179 if ( isEditing ) document . addEventListener ( 'keydown' , listenForSubmit )
222180 return ( ) => document . removeEventListener ( 'keydown' , listenForSubmit )
@@ -227,6 +185,16 @@ const useKeyboardListener = (
227185 handleEdit ( )
228186 } else if ( event . key === 'Escape' ) handleCancel ( )
229187 }
188+
189+ return (
190+ < div
191+ onDoubleClick = { ( ) => setIsEditing ( true ) }
192+ className = "jer-value-null"
193+ style = { getStyles ( 'null' , nodeData ) }
194+ >
195+ { String ( value ) }
196+ </ div >
197+ )
230198}
231199
232200export const InvalidValue : React . FC < InputProps > = ( { value } ) => {
0 commit comments