mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-21 14:47:46 -04:00
fix(KeyValue Editor): Pressing enter on an input should update the value (#7580)
* fix onKeydown using the previous value * use keybindingHandler for improved keyboard support
This commit is contained in:
@@ -3,6 +3,7 @@ import React, { FC, Fragment, useCallback, useRef, useState } from 'react';
|
||||
import { FocusScope } from 'react-aria';
|
||||
import { Button, Dialog, DialogTrigger, DropIndicator, GridList, GridListItem, Menu, MenuItem, MenuTrigger, Popover, ToggleButton, Toolbar, useDragAndDrop } from 'react-aria-components';
|
||||
import { useListData } from 'react-stately';
|
||||
import { createKeybindingsHandler } from 'tinykeys';
|
||||
|
||||
import { describeByteSize, generateId } from '../../../common/misc';
|
||||
import { useNunjucksEnabled } from '../../context/nunjucks/nunjucks-enabled-context';
|
||||
@@ -54,6 +55,20 @@ const EditableOneLineEditorModal = ({
|
||||
}
|
||||
}, [buttonRef]);
|
||||
|
||||
const onKeydown = useCallback((e: KeyboardEvent, value: string) => {
|
||||
const handler = createKeybindingsHandler({
|
||||
'Enter': e => {
|
||||
e.preventDefault();
|
||||
setIsOpen(false);
|
||||
onChange(value);
|
||||
setValue(value);
|
||||
},
|
||||
});
|
||||
|
||||
handler(e);
|
||||
},
|
||||
[onChange]);
|
||||
|
||||
useResizeObserver({
|
||||
ref: buttonRef,
|
||||
onResize: onResize,
|
||||
@@ -116,13 +131,7 @@ const EditableOneLineEditorModal = ({
|
||||
readOnly={readOnly}
|
||||
getAutocompleteConstants={getAutocompleteConstants}
|
||||
onChange={setValue}
|
||||
onKeyDown={e => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
onChange(value);
|
||||
setIsOpen(false);
|
||||
}
|
||||
}}
|
||||
onKeyDown={onKeydown}
|
||||
/>
|
||||
</div>
|
||||
</FocusScope>
|
||||
|
||||
Reference in New Issue
Block a user