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

241
Visualizações
Cómo borrar TextField después de presionar la tecla ENTER en React

Estoy usando el componente TextField de Mui en TypeSCript y quiero borrar TextField después de presionar la tecla ENTER.

Aquí está mi fragmento de código

 <TextField {...params} autoFocus className="SymbolInput" onChange={(e) => { setSearchTerm(e.target.value); handleInputdebounced(e.target.value); }} onBlur={clearState} onFocus={() => setSearchResults([])} placeholder="Add symbols" name="searchname" onKeyPress={(e) => { if (e.key === 'Enter') { onPressEnter(); setSearchTerm(''); } }} InputProps={{ ...params.InputProps, type: 'search', sx: { pb: '2px', pt: '2px' }, endAdornment: ( <InputAdornment position="end" sx={{width:0}}> {loading ? <CircularProgress color="inherit" size={20} /> : <SearchIcon />} </InputAdornment> ), }} inputProps={{ ...params.inputProps, sx: { textTransform: 'uppercase', }, }} /> const onPressEnter = async () => { if (searchTerm && searchTerm.length > 0) { onAddSymbol(searchTerm); } }; const handleSearchChange = async (searchTerm: string) => { const searchValue = searchTerm; //Check if there are any previous pending requests if (typeof autoCompleteCancelToken != typeof undefined) { autoCompleteCancelToken?.cancel('Operation canceled due to new request.'); } //Save the cancel token for the current request autoCompleteCancelToken = axios.CancelToken.source(); if (searchValue && searchValue.length > 0) { setLoading(true); setSearchTerm(searchTerm); const response = await companyLookup(searchTerm, { cancelToken: autoCompleteCancelToken?.token }); if (!response.hasErrors) { setSearchResults(response.data || []); } setGetValue(searchValue); setEditable(false); setLoading(false); } if (searchValue.length == 0) { setSearchResults([]); } }; const handleInputdebounced = useMemo(() => debounce(handleSearchChange, 200), []);

Estoy configurando el valor de textfield (searchTerm) en setSearchTersm useState pero no funciona.

¿Alguien puede ayudarme con esto?

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

0

<TextField {...params} value={searchTerm} autoFocus className="SymbolInput" onChange={(e) => { setSearchTerm(e.target.value); handleInputdebounced(e.target.value); }} onBlur={clearState} onFocus={() => setSearchResults([])} placeholder="Add symbols" name="searchname" onKeyPress={(e) => { if (e.key === 'Enter') { onPressEnter(); setSearchTerm(''); } }} InputProps={{ ...params.InputProps, type: 'search', sx: { pb: '2px', pt: '2px' }, endAdornment: ( <InputAdornment position="end" sx={{width:0}}> {loading ? <CircularProgress color="inherit" size={20} /> : <SearchIcon />} </InputAdornment> ), }} inputProps={{ ...params.inputProps, sx: { textTransform: 'uppercase', }, }} />

Simplemente agregue una propiedad de valor a TextField y asígnela a searchTerm (searchTerm es la variable de estado). Espero que esto resuelva tu problema. Por favor vota si es así :)

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