Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: address input issue #2918

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 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,19 @@ const TextField = React.forwardRef(
ref: React.LegacyRef<HTMLDivElement>
) => {
const [isPasswordHidden, setIsPasswordHidden] = useState(true)
const inputRef = useRef<any>()
Keith-CY marked this conversation as resolved.
Show resolved Hide resolved
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()
Keith-CY marked this conversation as resolved.
Show resolved Hide resolved
const position = value?.length || 0
inputRef.current.setSelectionRange(position, position)
}, [rows])

return (
<div
className={`${styles.textField} ${stack ? styles.stack : ''} ${className}`}
Expand All @@ -84,6 +92,7 @@ const TextField = React.forwardRef(
<textarea
id={field}
data-field={field}
ref={inputRef}
rows={rows}
value={value}
placeholder={placeholder}
Expand All @@ -100,6 +109,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