From 20564543ac078df7c54373162cd042f6bdd20261 Mon Sep 17 00:00:00 2001 From: Evgeniy Date: Mon, 27 May 2024 13:25:20 +0300 Subject: [PATCH] Search: Fix crating new item wit disabled menu --- src/form/Select/Select.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/form/Select/Select.tsx b/src/form/Select/Select.tsx index 656c70bb..1472dc57 100644 --- a/src/form/Select/Select.tsx +++ b/src/form/Select/Select.tsx @@ -285,7 +285,8 @@ export const Select: FC = ({ options, { keys: ['children', 'group'], - ...searchOptions + ...searchOptions, + getFn: menuDisabled ? () => '' : searchOptions?.getFn } ); @@ -551,13 +552,26 @@ export const Select: FC = ({ } else { newSelection = result[index]; } - - if (newSelection) { + // Add new item if menu not disabled or item not presents in the list otherwise just clear input + if ( + newSelection && + (!menuDisabled || !value.includes(newSelection.value)) + ) { toggleSelectedOption(newSelection); + } else if (menuDisabled && value.includes(newSelection.value)) { + resetInput(); } } }, - [createable, index, result, toggleSelectedOption] + [ + createable, + index, + menuDisabled, + resetInput, + result, + toggleSelectedOption, + value + ] ); const onTabKeyDown = useCallback(