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

fixed autocompelete issue #1300

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 10 additions & 11 deletions packages/fuselage/src/components/AutoComplete/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ export function AutoComplete({
);

const handleSelect = useEffectEvent(([currentValue]) => {
if (selected?.some((item) => item.value === currentValue)) {
hide();
return;
}
if (!currentValue) return; // Exit early if no value is selected

if (multiple) {
const newValue = Array.isArray(value)
? [...value, currentValue]
: [currentValue];
setSelected([...selected, ...getSelected(currentValue, options)]);
onChange([...value, currentValue]);
onChange(newValue);
} else {
setSelected(getSelected(currentValue, options));
onChange(currentValue);
Expand All @@ -98,13 +98,12 @@ export function AutoComplete({
event.stopPropagation();
event.preventDefault();

const filtered = selected.filter(
(item) => item.value !== event.currentTarget.value
);
const removedValue = event.currentTarget.value;

const filteredValue = value.filter(
(item) => item !== event.currentTarget.value
);
const filtered = selected.filter((item) => item.value !== removedValue);
const filteredValue = Array.isArray(value)
? value.filter((item) => item !== removedValue)
: [];

setSelected(filtered);
onChange(filteredValue);
Expand Down
Loading