Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

421
Visualizações
MUI TextField component with focus and active cursor

I'm using the MUI TextField component as a single input form. When the component loads it has focus, but no cursor to begin typing. The user still has to click into the input to bring up the cursor and begin typing. Alternatively, the user can click the tab key and the cursor come up. But typing anything else doesn't activate the cursor or register any characters in the TextField. I tried using the autoFocus attribute, as well as: inputRef={input => input && input.focus()} from this answer.

Here is the form:

<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>

And here is a picture of focus with no cursor: TextField with focus but no cursor

And a picture of focus with the cursor after clicking in: TextField with focus and cursor

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can do it this way:

function MyComponent () {
const inputRef = useRef(null);
useEffect(() => {
  inputRef.current.focus()
}, [])
return (
    <TextField inputRef={inputRef} id="new-comment" label="Comment" />
);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda