close the menu when input doesn't match but user hits enter

This commit is contained in:
Oleg Isonen committed 2022-10-15 18:05:32 +02:00
1 parent f7a647abb4
commit c76e807989
1 file changed
+6 -2
@@ -188,14 +188,18 @@ const useKeyDown =
onChange,
onChangeComplete,
onKeyDown,
closeMenu,
}: {
value: StyleValue;
onChange: (value: StyleValue) => void;
onChangeComplete: (value: StyleValue) => void;
onKeyDown: KeyboardEventHandler<HTMLInputElement>;
closeMenu: () => void;
}) =>
(event: KeyboardEvent<HTMLInputElement>) => {
onKeyDown(event);
if (event.key === "Enter") {
closeMenu();
onChangeComplete(value);
}
if (
@@ -207,8 +211,6 @@ const useKeyDown =
value: calcNumberChange(value.value, event),
});
}
onKeyDown(event);
};
type CssValueInputProps = {
@@ -268,6 +270,7 @@ export const CssValueInput = ({
getMenuProps,
getItemProps,
isOpen,
closeMenu,
} = useCombobox<StyleValue>({
items: keywords,
value,
@@ -305,6 +308,7 @@ export const CssValueInput = ({
onChange,
onChangeComplete,
onKeyDown: inputProps.onKeyDown,
closeMenu,
});
const suffix =