• Jobs
  • About Us
  • Jobs
    • Home
    • Jobs
    • Courses and challenges
  • Businesses
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Hire tech talent
    • Blog
    • Sales
    • Salary Calculator

0

388
Views
Componente MUI TextField con foco y cursor activo

Estoy usando el componente MUI TextField como un formulario de entrada único. Cuando el componente se carga, tiene el foco, pero no el cursor para comenzar a escribir. El usuario aún tiene que hacer clic en la entrada para que aparezca el cursor y comenzar a escribir. Alternativamente, el usuario puede hacer clic en la tecla de tabulación y aparecer el cursor. Pero escribir cualquier otra cosa no activa el cursor ni registra ningún carácter en el TextField. Intenté usar el atributo autoFocus, así como: inputRef={input => input && input.focus()} de esta respuesta .

Aquí está el formulario:

 <FormControl variant="standard" fullWidth> <TextField id="new-comment" label="Comment" multiline minRows={3} maxRows={5} focused={true} value={comment} onChange={updateCommentValue} onKeyDown={keyPress} /> <Button onClick={saveComment}> Comment </Button> </FormControl>

Y aquí hay una imagen del foco sin cursor: TextField con foco pero sin cursor

Y una imagen de enfoque con el cursor después de hacer clic en: TextField con foco y cursor

almost 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes hacerlo de esta manera:

 function MyComponent () { const inputRef = useRef(null); useEffect(() => { inputRef.current.focus() }, []) return ( <TextField inputRef={inputRef} id="new-comment" label="Comment" /> ); }
almost 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!