Skip to content

Commit

Permalink
fix: address input issue (#2918)
Browse files Browse the repository at this point in the history
* fix: address input issue

* fix
  • Loading branch information
devchenyan authored Nov 9, 2023
1 parent 743fbd4 commit 5e33fe9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/neuron-ui/src/widgets/TextField/index.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -55,11 +55,28 @@ const TextField = React.forwardRef(
ref: React.LegacyRef<HTMLDivElement>
) => {
const [isPasswordHidden, setIsPasswordHidden] = useState(true)
const inputRef = useRef<(HTMLTextAreaElement & HTMLInputElement) | null>(null)
const rowsRef = useRef<number>(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 (
<div
className={`${styles.textField} ${stack ? styles.stack : ''} ${className}`}
Expand All @@ -84,6 +101,7 @@ const TextField = React.forwardRef(
<textarea
id={field}
data-field={field}
ref={inputRef}
rows={rows}
value={value}
placeholder={placeholder}
Expand All @@ -100,6 +118,7 @@ const TextField = React.forwardRef(
<input
id={field}
data-field={field}
ref={inputRef}
type={!isPasswordHidden && type === 'password' ? 'text' : type}
value={value}
placeholder={placeholder}
Expand Down

2 comments on commit 5e33fe9

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 6813346104

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 6813346221

Please sign in to comment.