Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: Fix creating new item wit disabled menu #216

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading