diff --git a/src/components/Input/InputTextBase/InputTextBase.tsx b/src/components/Input/InputTextBase/InputTextBase.tsx index 9834dead..4809b81e 100644 --- a/src/components/Input/InputTextBase/InputTextBase.tsx +++ b/src/components/Input/InputTextBase/InputTextBase.tsx @@ -176,11 +176,30 @@ export const InputTextBase = memo< [floatLabel, styles.iconSize, styles.iconSizeFloatLabel] ) + const imperativeHandle = useMemo( + () => + new Proxy( + {}, + { + get(_, prop) { + if (prop === 'clear') { + return clear + } + + const input = inputRef.current + const value = input?.[prop as keyof TextInput] + + return typeof value === 'function' ? value.bind(input) : value + }, + } + ) as TextInput, + [clear] + ) + useImperativeHandle( propsInputRef, - () => - inputRef.current ? Object.assign(inputRef.current, { clear }) : null, - [inputRef, clear] + () => (inputRef.current ? imperativeHandle : null), + [imperativeHandle] ) const { makeTestId } = useMakeTestId(