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

102
Visualizações
Scroll into a certain div that is hidden in the beggining

Im building a web chat app in next.js and i have a emoji picker button that when its clicked the menu of emojis appear.The thing is that in order to the user sees the menu of the emojis he has to scroll down.I have tried scrollIntoView() but it doesnt seem to work,possibly im doing something wrong.

 <EmoticonContainer >
        
    {showEmojis && (<Picker id="picker" style={{width: '100%'}} onSelect={addEmoji}/>)}
        
</EmoticonContainer>
<InputContainer id="container"  >
    <IconButton onClick={() => {setShowEmojis(!showEmojis),()=>document.getElementById('picker').scrollIntoView(true)}}>
        <EmojiEmotionsIcon style={{ color: 'purple' }} fontSize='inherit' />
    </IconButton>
    <Input style={{fontFamily:"Roboto",fontSize:"12px"}} onKeyUp={()=>ChangeSendIcon()} onKeyPress={(e) => { e.key === 'Enter' && e.preventDefault(); }} value={input} onChange={e=> setInput(e.target.value)}/>

    <div>
        <IconButton id="send" onClick={sendMessage} style={{ color: 'purple',display:'none' }} disabled={!input} type="submit">
            <SendIcon></SendIcon>
        </IconButton>
        <IconButton style={{ color: 'purple'}} id="record" onMouseUp={()=>record()}>
           <MicIcon ></MicIcon> 
        </IconButton>
        <IconButton style={{ color: 'purple',display:"none" }} onClick={()=>stop()} id="stop" >
           <StopIcon></StopIcon> 
        </IconButton>
    </div>

    
    
</InputContainer> 

I have tried this but it doesnt seem to work:

useEffect(() => {
 if(showEmojis) {
 document.getElementById('picker').scrollIntoView(true)
 }
} , [showEmojis])
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Instead of document.getElementById('picker').scrollIntoView(true) use the React.useRef() hook.

E.g. at the start of your function

const pickerRef = useRef()

then in your useEffect hook

useEffect(() => {
 if(showEmojis) {
     pickerRef.current.scrollIntoView(true)
 }
} , [showEmojis])

then in your return body

<Picker ref={pickerRef} id="picker" style={{width: '100%'}} onSelect={addEmoji}/>

It's not advised to use javascript query in jsx.

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