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

499
Visualizações
React Bootstrap- Overlay Tooltip rendering in wrong position initially

I am writing a react bootstrap app where a button appears at the end of an animation. When the button first appears, I want a tooltip to appear next to it. Once the user hovers over and off the button, the tooltip should go away and re-appear whenever the user hovers over the button again. I've gotten this to work as desired, but when I position the button where I want it to be (fixed to the bottom of the screen), the tooltip initially renders in the wrong position (where the button was before being positioned).

I have created two simple examples to demonstrate this behavior.

In the first example, the button is positioned at the top of the screen and the tooltip behaves as this desire:

function Testing(){
    const refLink = useRef(null);

    const [overlayOpen, setOverlayOpen]  = useState(true); // Initially open
    const [textDone, setTextDone] = useState(false);
    useEffect(() => {
        const timeoutId = setTimeout(() => {
            setTextDone(true)
        },1000)
        return () => clearTimeout(timeoutId)
    },[])
    return(
        <Container>
            <Row>
                {textDone ?
                    <>
                    <Button ref={refLink} onMouseOver={() => setOverlayOpen(true)}
                            onMouseOut={() => setOverlayOpen(false)}
                    >
                        <FaComment/>
                    </Button>
                    <Overlay target={refLink.current} show={overlayOpen}
                             onHide={() => setOverlayOpen(false)} rootClose placement={"bottom"}>
                        <Tooltip>
                            Submit a personal response!
                        </Tooltip>
                    </Overlay>
                    </>
                    : ''
                }
            </Row>
        </Container>
   )
}

export default Testing

The textDone state is set to true once the "animation" finishes. To simplify the example, I omitted the animation itself and recreated the delay with setTimeout.

The second example is identical except for the following .css class added to the Row element in which the button, overlay, and tooltip are nested inside of.

.fixed-button{
    position:fixed;
    right: 20px;
    bottom: 20px;
}

With this addition, the button ends up where I want it, but the tooltip first appears at the top of the screen. Once I hover over the button, the tooltip moves to the correct position.

Here are some gifs of the two examples.

Example 1 (tooltip behaving as intended but button not positioned in right spot)

Example 2 (button positioned where I want it but tooltip initially showing up in wrong spot)

My question is: how can I get the tooltip to initially appear in the correct position?

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