Skip to content

Commit

Permalink
Merge pull request #216 from reaviz/search/fix_items_creating
Browse files Browse the repository at this point in the history
Search: Fix creating new item wit disabled menu
  • Loading branch information
evgenoid authored May 27, 2024
2 parents c029b62 + 2056454 commit a4f0c3d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/form/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ export const Select: FC<SelectProps> = ({
options,
{
keys: ['children', 'group'],
...searchOptions
...searchOptions,
getFn: menuDisabled ? () => '' : searchOptions?.getFn
}
);

Expand Down Expand Up @@ -551,13 +552,26 @@ export const Select: FC<SelectProps> = ({
} 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(
Expand Down

0 comments on commit a4f0c3d

Please sign in to comment.