Skip to content

Commit 69aaabc

Browse files
authored
Fix Ref Assignemnt (#146)
1 parent c5967ed commit 69aaabc

3 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+
- fix ref assignment for `StaticTypeaheadInput` and nd `AsyncTypeaheadInput`in order to redirect `input field` in case of error
13+
1014
## [3.10.1] - 2025-09-23
1115

1216
### Fixed

src/lib/AsyncTypeaheadInput.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ const AsyncTypeaheadInput = <T extends FieldValues>(props: AsyncTypeaheadInputPr
8686

8787
validateFixedOptions(fixedOptions, multiple, autocompleteProps, withFixedOptionsInValue, value);
8888

89-
const { field } = useController({
89+
const {
90+
field: { ref, ...field },
91+
} = useController({
9092
name,
9193
control,
9294
rules: {
@@ -225,7 +227,7 @@ const AsyncTypeaheadInput = <T extends FieldValues>(props: AsyncTypeaheadInputPr
225227
loadMoreOptions={loadMoreOptions}
226228
setPage={setPage}
227229
{...params}
228-
inputRef={(elem) => field.ref(elem)}
230+
inputRef={(elem) => ref(elem)}
229231
/>
230232
)}
231233
renderTags={createTagRenderer(fixedOptions, autocompleteProps)}

src/lib/StaticTypeaheadInput.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ const StaticTypeaheadInput = <T extends FieldValues>(props: StaticTypeaheadInput
7272

7373
const { name, id } = useSafeNameId(props.name ?? "", props.id);
7474
const { control, disabled: formDisabled, getFieldState, clearErrors, watch } = useFormContext();
75-
const { field } = useController({
75+
const {
76+
field: { ref, ...field },
77+
} = useController({
7678
name,
7779
control,
7880
rules: {
@@ -190,7 +192,7 @@ const StaticTypeaheadInput = <T extends FieldValues>(props: StaticTypeaheadInput
190192
loadMoreOptions={loadMoreOptions}
191193
setPage={setPage}
192194
{...params}
193-
inputRef={(elem) => field.ref(elem)}
195+
inputRef={(elem) => ref(elem)}
194196
/>
195197
)}
196198
renderTags={createTagRenderer(fixedOptions, autocompleteProps)}

0 commit comments

Comments
 (0)