Skip to content

Commit 9b0e9fd

Browse files
solution
1 parent 4a8cfb6 commit 9b0e9fd

5 files changed

Lines changed: 12 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- `onChange` into `StaticTypeaheadInput` and `AsyncTypeaheadInput` to support async functions.
13+
1014
## [4.0.0] - 2026-02-24
1115

1216
### Changed

src/lib/AsyncTypeaheadInput.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ const AsyncTypeaheadInput = <T extends FieldValues>(props: AsyncTypeaheadInputPr
195195
const values = convertAutoCompleteOptionsToStringArray(optionsArray);
196196
const finalValue = multiple ? values : values[0];
197197
if (onChange) {
198-
onChange(finalValue);
198+
void (async () => {
199+
await onChange(finalValue);
200+
})();
199201
}
200202
field.onChange(finalValue);
201203
}}

src/lib/StaticTypeaheadInput.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ const StaticTypeaheadInput = <T extends FieldValues>(props: StaticTypeaheadInput
166166
const finalValue = multiple ? values : values[0];
167167
clearErrors(field.name);
168168
if (onChange) {
169-
onChange(finalValue);
169+
void (async () => {
170+
await onChange(finalValue);
171+
})();
170172
}
171173
field.onChange(finalValue);
172174
}}

src/lib/hooks/useDebounceHook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const useDebounceHook = (queryFn: (query: string) => Promise<TypeaheadOptions>,
6060
return;
6161
}, [queryFn, setOptions, debounceSearch]);
6262

63-
return { setDebounceSearch, isLoading };
63+
return { setDebounceSearch, isLoading, queryRef };
6464
};
6565

6666
export { useDebounceHook };

src/lib/types/Typeahead.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface CommonTypeaheadProps<T extends FieldValues> extends Omit<
2929
innerRef?: RefObject<HTMLInputElement | null>;
3030
fitMenuContent?: boolean;
3131
getOptionDisabled?: (option: TypeaheadOption) => boolean;
32-
onChange?: (selected: string | string[]) => void;
32+
onChange?: (selected: string | string[]) => void | Promise<void>;
3333
onInputChange?: (text: string, reason: AutocompleteInputChangeReason) => void;
3434
onClose?: (event: SyntheticEvent, reason: AutocompleteCloseReason) => void;
3535
onOpen?: (event: SyntheticEvent) => void;

0 commit comments

Comments
 (0)