Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

css - How to stop scrollbar from auto scrolling when component updates

I am using this library https://www.npmjs.com/package/react-perfect-scrollbar the scroll bar is set up around a comment section where new comments are shown at the top. When a new comment is added to the top of the component it updates and the scroll bar automatically goes to the bottom of the component. Any idea how i can stop it from updating it's position when the component updates?

here's how the section of the function that sets up the container is set-up, children object contains the list which is managed in a different component.

  const Container: FC<HTMLAttributes<HTMLDivElement>> = useCallback(
    props =>
      match ? (
        <PerfectScrollbar className={classes.scrollContainer} {...props} />
      ) : (
        <div className={classes.staticContainer} {...props} />
      ),
    [match]
  )

  return (
    <Grid item {...gridProps} classes={{ item: classNames({ [classes.gridScroll]: match }) }}>
      <Container>{children}</Container>
    </Grid>
  )

below is the css for classes.scrollContainer and classes.gridScroll

    scrollContainer: {
      padding: spacing(1),
      paddingTop: spacing(4),
      height: '100%'
    },
    gridScroll: {
      height: '100%',
      '&:last-child': {
        '& $scrollContainer': {
          paddingBottom: spacing(4)
        }
      }
    },

I am trying to get it to not scroll to the bottom when the component is updated.

Thank You

question from:https://stackoverflow.com/questions/65834509/how-to-stop-scrollbar-from-auto-scrolling-when-component-updates

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...