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

147
Visualizações
Having onBlur event fire on certain conditions React

I have bound an onBlur on my textarea to blur the input and essentially hide it if the user clicks anywhere outside of it.

My function to edit a comment:

              <div key={idx} className='comments-container__cols__comments' style={toggleItem ? null : { opacity: '0.3' }}>
                {isEditing.includes(comment) ? (
                  <div className='textarea-container'>
                    <textarea
                      autoFocus
                      id='text-area-reports-comments'
                      type='text'
                      value={editingPost}
                      onBlur={onBlurEdit}
                      onChange={(e) => setEditingPost(e.target.value)}
                    />
                    <span ref={submitBtnRef}>
                      <RiSendPlaneFill onClick={handleEditPost} />
                    </span>
                  </div>

The problem I have is that I have positioned my span inside my input with position: absolute. If I click on the span the input gets blurred and my handleEditPost function doesn't fire. I still do want the input to blur but I need my function to run first. Any advice would be great.

onBlurEdit

  const onBlurEdit = () => {
    setIsEditing([])
    setEditingPost('')
  }

handleEditPost

  const handleEditPost = async () => {
    if (editingPost.length > 3) {
      try {
        const idx = comments.indexOf(isEditing[0])
        let newArr = [...comments]

        const { data } = await editVolunteerReport(isEditing[0].id, editingPost)

        newArr[idx] = data
        setComments(newArr)

        onBlurEdit()
      } catch (err) {
        console.log(err.message)
      }
    } else {
      return
    }
  }
about 4 years ago · Juan Pablo Isaza
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