Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
Desplácese a un cierto div que está oculto al principio

Estoy creando una aplicación de chat web en next.js y tengo un botón selector de emoji que cuando se hace clic en el menú de emojis aparece. La cuestión es que para que el usuario vea el menú de emojis, tiene que desplazarse hacia abajo. Tengo probé scrollIntoView() pero no parece funcionar, posiblemente estoy haciendo algo mal.

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

He intentado esto pero no parece funcionar:

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

0

En lugar de document.getElementById('picker').scrollIntoView(true) usa el gancho React.useRef() .

Por ejemplo, al comienzo de su función

 const pickerRef = useRef()

luego en tu gancho useEffect

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

luego en tu cuerpo de vuelta

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

No se recomienda utilizar la consulta de javascript en jsx.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!