How can I scroll a div to be visible in ReactJS?

前端 未结 9 1542
梦如初夏
梦如初夏 2020-12-04 15:25

I have a popup list which is a div that contains a vertical list of child divs. I have added up/down keyboard navigation to change which child is

9条回答
  •  星月不相逢
    2020-12-04 15:53

    Just in case someone stumbles here, I did it this way

      componentDidMount(){
        const node = this.refs.trackerRef;
        node && node.scrollIntoView({block: "end", behavior: 'smooth'})
      }
      componentDidUpdate() {
        const node = this.refs.trackerRef;
        node && node.scrollIntoView({block: "end", behavior: 'smooth'})
      }
    
      render() {
        return (
    
          
    {messages.map((msg, index) => { return ( some test text

    */}
    ) })}
    ) }

    scrollIntoView is native DOM feature link

    It will always shows tracker div

提交回复
热议问题