Skip to content

Manage scroll programmatically #696

Answered by jjenzz
olup asked this question in Help
Jun 8, 2021 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

This will all be much easier when we release the new version:

const viewportRef = React.useRef<React.ElementRef<typeof ScrollArea.Viewport>>(null);

React.useEffect(() => {
  viewportRef.current?.scrollTop = 100;
}, []);

return (
	<ScrollArea.Root type="hover" scrollHideDelay={600}>
  		<ScrollArea.Viewport ref={viewportRef} id="whatever-you-like">
			Lots of content...
  		</ScrollArea.Viewport>
  		<ScrollArea.Scrollbar orientation="horizontal">
    		<ScrollArea.Thumb />
  		</ScrollArea.Scrollbar>
  		<ScrollArea.Scrollbar orientation="vertical">
    		<ScrollArea.Thumb />
  		</ScrollArea.Scrollbar>
  		<ScrollArea.Corner />
	</ScrollArea.Root>
);

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@olup
Comment options

@benoitgrelard
Comment options

@olup
Comment options

@benoitgrelard
Comment options

Answer selected by olup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants