✨(react) add onSearchInputChange callback to searchable select
We want to be able to notify an event when the search term of the searchable select gets updated.
This commit is contained in:
@@ -16,7 +16,7 @@ import { SelectHandle } from ":/components/Forms/Select/index";
|
||||
|
||||
export const SelectMultiSearchable = forwardRef<SelectHandle, SubProps>(
|
||||
(props, ref) => {
|
||||
const [inputValue, setInputValue] = React.useState<string>("");
|
||||
const [inputValue, setInputValue] = React.useState<string>();
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const options = React.useMemo(
|
||||
() =>
|
||||
@@ -75,11 +75,11 @@ export const SelectMultiSearchable = forwardRef<SelectHandle, SubProps>(
|
||||
...props.selectedItems,
|
||||
newSelectedItem,
|
||||
]);
|
||||
setInputValue("");
|
||||
setInputValue(undefined);
|
||||
}
|
||||
break;
|
||||
case useCombobox.stateChangeTypes.InputChange:
|
||||
setInputValue(newInputValue ?? "");
|
||||
setInputValue(newInputValue);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -124,6 +124,10 @@ export const SelectMultiSearchable = forwardRef<SelectHandle, SubProps>(
|
||||
},
|
||||
}));
|
||||
|
||||
useEffect(() => {
|
||||
props.onSearchInputChange?.({ target: { value: inputValue } });
|
||||
}, [inputValue]);
|
||||
|
||||
return (
|
||||
<SelectMultiAux
|
||||
{...props}
|
||||
|
||||
Reference in New Issue
Block a user