diff --git a/packages/neuron-ui/src/widgets/TextField/index.tsx b/packages/neuron-ui/src/widgets/TextField/index.tsx index 2f86f88783..3f2208d302 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,28 @@ const TextField = React.forwardRef( ref: React.LegacyRef ) => { const [isPasswordHidden, setIsPasswordHidden] = useState(true) + const inputRef = useRef<(HTMLTextAreaElement & HTMLInputElement) | null>(null) + const rowsRef = useRef(rows) 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(() => { + 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) + }, [rows]) + return (