From ab23bb1ca810550158e943910276ad9cfe70c250 Mon Sep 17 00:00:00 2001 From: Shubham Choudhary Date: Mon, 13 Jan 2025 17:00:48 +0530 Subject: [PATCH 1/2] fix: issue when uncontrolled input value is get programmatically i.e without typing We have a use case which I feel is very common. We have remark suggestions for an entry. Once suggestion is picked and value is set using setNativeProps method uncontrolledValue is not updated this is resulting input label and palceholder to get overlapped. --- src/components/TextInput/TextInput.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/TextInput/TextInput.tsx b/src/components/TextInput/TextInput.tsx index aaea38a3b5..38b4bd79e3 100644 --- a/src/components/TextInput/TextInput.tsx +++ b/src/components/TextInput/TextInput.tsx @@ -290,7 +290,13 @@ const TextInput = forwardRef( React.useImperativeHandle(ref, () => ({ focus: () => root.current?.focus(), clear: () => root.current?.clear(), - setNativeProps: (args: Object) => root.current?.setNativeProps(args), + setNativeProps: (args: Object) => { + if ('text' in args) { + // Update uncontrolledValue when text is set via setNativeProps + setUncontrolledValue(args.text as string); + } + root.current?.setNativeProps(args); + }, isFocused: () => root.current?.isFocused() || false, blur: () => root.current?.blur(), forceFocus: () => root.current?.focus(), From 712b9e05e93c2051aeccb7343a984d8bad60e599 Mon Sep 17 00:00:00 2001 From: shubhamdeol Date: Tue, 14 Jan 2025 19:43:28 +0530 Subject: [PATCH 2/2] chore: resolve build issue --- src/components/TextInput/TextInput.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/TextInput/TextInput.tsx b/src/components/TextInput/TextInput.tsx index 38b4bd79e3..60b4834d15 100644 --- a/src/components/TextInput/TextInput.tsx +++ b/src/components/TextInput/TextInput.tsx @@ -290,7 +290,7 @@ const TextInput = forwardRef( React.useImperativeHandle(ref, () => ({ focus: () => root.current?.focus(), clear: () => root.current?.clear(), - setNativeProps: (args: Object) => { + setNativeProps: (args: { text?: string } & Object) => { if ('text' in args) { // Update uncontrolledValue when text is set via setNativeProps setUncontrolledValue(args.text as string);