Fixed new input field focus

pull/1575/head
ioedeveloper 3 years ago
parent 7c5ad3934e
commit 4bdddefb2c
  1. 14
      libs/remix-ui/workspace/src/lib/components/file-label.tsx
  2. 1
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -15,12 +15,18 @@ export interface FileLabelProps {
export const FileLabel = (props: FileLabelProps) => {
const { file, focusEdit, editModeOff } = props
const isEditable = focusEdit.element === file.path
const [isEditable, setIsEditable] = useState<boolean>(false)
const labelRef = useRef(null)
const [defaultValue, setDefaultValue] = useState<string>(null)
useEffect(() => {
if (isEditable) {
if (focusEdit.element && file.path) {
setIsEditable(focusEdit.element === file.path)
}
}, [file.path, focusEdit])
useEffect(() => {
if (labelRef.current) {
setTimeout(() => {
labelRef.current.focus()
}, 0)
@ -28,7 +34,7 @@ export const FileLabel = (props: FileLabelProps) => {
}, [isEditable])
useEffect(() => {
setDefaultValue(labelRef.current.innerText)
if (labelRef.current) setDefaultValue(labelRef.current.innerText)
}, [labelRef.current])
const handleEditInput = (event: React.KeyboardEvent<HTMLDivElement>) => {
@ -48,7 +54,7 @@ export const FileLabel = (props: FileLabelProps) => {
return (
<div
className='remixui_items d-inline-block w-100'
ref={labelRef}
ref={isEditable ? labelRef : null}
suppressContentEditableWarning={true}
contentEditable={isEditable}
onKeyDown={handleEditInput}

@ -21,6 +21,7 @@ export function Workspace () {
useEffect(() => {
global.dispatchInitWorkspace()
resetFocus()
}, [])
useEffect(() => {

Loading…
Cancel
Save