From eb810aaee14853b3d27eee4728ab66dc679e9006 Mon Sep 17 00:00:00 2001 From: chenyan Date: Mon, 6 Nov 2023 15:36:18 +0800 Subject: [PATCH 1/2] fix: address input issue --- packages/neuron-ui/src/widgets/TextField/index.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/neuron-ui/src/widgets/TextField/index.tsx b/packages/neuron-ui/src/widgets/TextField/index.tsx index 2f86f88783..572b81b930 100644 --- a/packages/neuron-ui/src/widgets/TextField/index.tsx +++ b/packages/neuron-ui/src/widgets/TextField/index.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useRef, useState } from 'react' +import React, { useCallback, useRef, useState, useEffect } from 'react' import Alert from 'widgets/Alert' import { ReactComponent as Edit } from 'widgets/Icons/Edit.svg' import { EyesClose, EyesOpen } from 'widgets/Icons/icon' @@ -55,11 +55,19 @@ const TextField = React.forwardRef( ref: React.LegacyRef ) => { const [isPasswordHidden, setIsPasswordHidden] = useState(true) + const inputRef = useRef() const changePasswordHide = useCallback(() => { setIsPasswordHidden(v => !v) }, [setIsPasswordHidden]) // FIXME: label should be limited to a string because it has its own semantic meaning const labelStr = typeof label === 'string' ? label : field + + useEffect(() => { + inputRef.current.focus() + const position = value?.length || 0 + inputRef.current.setSelectionRange(position, position) + }, [rows]) + return (
Date: Thu, 9 Nov 2023 13:38:35 +0800 Subject: [PATCH 2/2] fix --- packages/neuron-ui/src/widgets/TextField/index.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/neuron-ui/src/widgets/TextField/index.tsx b/packages/neuron-ui/src/widgets/TextField/index.tsx index 572b81b930..3f2208d302 100644 --- a/packages/neuron-ui/src/widgets/TextField/index.tsx +++ b/packages/neuron-ui/src/widgets/TextField/index.tsx @@ -55,7 +55,8 @@ const TextField = React.forwardRef( ref: React.LegacyRef ) => { const [isPasswordHidden, setIsPasswordHidden] = useState(true) - const inputRef = useRef() + const inputRef = useRef<(HTMLTextAreaElement & HTMLInputElement) | null>(null) + const rowsRef = useRef(rows) const changePasswordHide = useCallback(() => { setIsPasswordHidden(v => !v) }, [setIsPasswordHidden]) @@ -63,6 +64,14 @@ const TextField = React.forwardRef( const labelStr = typeof label === 'string' ? label : field useEffect(() => { + if (rowsRef.current === rows) { + return + } + + rowsRef.current = rows + if (!inputRef.current) { + return + } inputRef.current.focus() const position = value?.length || 0 inputRef.current.setSelectionRange(position, position)