diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aeb9fd..8954d0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `onChange` into `StaticTypeaheadInput` and `AsyncTypeaheadInput` to support async functions. +- `onInputChange` into `StaticTypeaheadInput` and `AsyncTypeaheadInput` to support async functions. +- `useDebounceHook` in order to expose the `queryRef` (which keeps track of the search input value) + ## [4.0.0] - 2026-02-24 ### Changed diff --git a/src/lib/AsyncTypeaheadInput.tsx b/src/lib/AsyncTypeaheadInput.tsx index bacc0aa..36979a7 100644 --- a/src/lib/AsyncTypeaheadInput.tsx +++ b/src/lib/AsyncTypeaheadInput.tsx @@ -195,7 +195,7 @@ const AsyncTypeaheadInput = (props: AsyncTypeaheadInputPr const values = convertAutoCompleteOptionsToStringArray(optionsArray); const finalValue = multiple ? values : values[0]; if (onChange) { - onChange(finalValue); + void (async () => await onChange(finalValue))(); } field.onChange(finalValue); }} @@ -207,7 +207,7 @@ const AsyncTypeaheadInput = (props: AsyncTypeaheadInputPr setDebounceSearch({ delay, query }); } if (onInputChange) { - onInputChange(query, reason); + void (async () => await onInputChange(query, reason))(); } }} renderOption={highlightOptions ? renderHighlightedOptionFunction : undefined} diff --git a/src/lib/StaticTypeaheadInput.tsx b/src/lib/StaticTypeaheadInput.tsx index b252255..ea65671 100644 --- a/src/lib/StaticTypeaheadInput.tsx +++ b/src/lib/StaticTypeaheadInput.tsx @@ -166,13 +166,13 @@ const StaticTypeaheadInput = (props: StaticTypeaheadInput const finalValue = multiple ? values : values[0]; clearErrors(field.name); if (onChange) { - onChange(finalValue); + void (async () => await onChange(finalValue))(); } field.onChange(finalValue); }} onInputChange={(_e, value, reason) => { if (onInputChange) { - onInputChange(value, reason); + void (async () => await onInputChange(value, reason))(); } }} renderOption={highlightOptions ? renderHighlightedOptionFunction : undefined} diff --git a/src/lib/hooks/useDebounceHook.ts b/src/lib/hooks/useDebounceHook.ts index 0952eed..2ed2854 100644 --- a/src/lib/hooks/useDebounceHook.ts +++ b/src/lib/hooks/useDebounceHook.ts @@ -60,7 +60,7 @@ const useDebounceHook = (queryFn: (query: string) => Promise, return; }, [queryFn, setOptions, debounceSearch]); - return { setDebounceSearch, isLoading }; + return { setDebounceSearch, isLoading, queryRef }; }; export { useDebounceHook }; diff --git a/src/lib/types/Typeahead.ts b/src/lib/types/Typeahead.ts index d34d5d9..ef6ff52 100644 --- a/src/lib/types/Typeahead.ts +++ b/src/lib/types/Typeahead.ts @@ -29,8 +29,8 @@ interface CommonTypeaheadProps extends Omit< innerRef?: RefObject; fitMenuContent?: boolean; getOptionDisabled?: (option: TypeaheadOption) => boolean; - onChange?: (selected: string | string[]) => void; - onInputChange?: (text: string, reason: AutocompleteInputChangeReason) => void; + onChange?: (selected: string | string[]) => void | Promise; + onInputChange?: (text: string, reason: AutocompleteInputChangeReason) => void | Promise; onClose?: (event: SyntheticEvent, reason: AutocompleteCloseReason) => void; onOpen?: (event: SyntheticEvent) => void; onBlur?: () => void;