Proposal ScrollArea | Make it possible to control Scroll Area programmatically #990
-
It should be possible to control Scroll Area programmatically, I think it should also support custom easing functions, or perhaps it should be able to integrate with other animations libraries. Here is an example how it could look like: const Component = () => {
const scrollArea = useScrollArea();
// Ref used some where in a component inside ScrollArea component
const ref = useRef();
const onClickHandler = () => {
scrollArea.scrollToElement(ref)
// or
scrollArea.scrollToTop();
// or
scrollArea.scrollToBottom();
}
return (
<>
<button onClikc={onClickHandler}>
Scroll To
</button>
<ScrollArea.Root>
...
</ScrollArea.Root>
</>
);
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi @joseDaKing, As I explained in your other discussion post (#989 (comment)) you have full access to the underlying scrolling div, so you can totally control it programatically. Here's an example: |
Beta Was this translation helpful? Give feedback.
-
If anyone stumbles upon this, this is how to do it:
If you are using shadcn, extend the props so you can pass the ref to the
|
Beta Was this translation helpful? Give feedback.
Hi @joseDaKing,
As I explained in your other discussion post (#989 (comment)) you have full access to the underlying scrolling div, so you can totally control it programatically.
Here's an example:
https://codesandbox.io/s/scrollarea-programatic-q66k7