ScrollArea documentation need to mention how to get scrollX and scrollY position #3404
InconstantUA
started this conversation in
General
Replies: 2 comments 2 replies
-
To get ScrollX and ScrollY value of your scrollable component, you can simply use <ScrollArea
className="w-full h-[800px]"
onScrollCapture={(event) => {
console.log(event.target.scrollLeft); // Scroll X
console.log(event.target.scrollTop); // Scroll Y
console.log(event.target.scrollHeight); // Max Constraint Height
console.log(event.target.scrollWidth); // Max Constraint Width
}}
>
<div>...</div>
<ScrollBar/>
</ScrollArea> |
Beta Was this translation helpful? Give feedback.
1 reply
-
I actually need to be able to control it. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Please update ScrollArea documentation. Please explain how to get scrollX and scrollY position. Because it took me several days to find out how to handle it. I want to share this information here and also prevent other users in future from stepping into the same pit. By default when you google for the solution it will tell you to use window.scrollx and scrollY position to get scroll offset. But with ScrollArea component, in fact, this should done in completely different way:
This should be queried on ScrollAreaPrimitive.Viewport component. For this, I need also get reference to this component.
So i had to modify source code like this:
In my .tsx file I need to do this:
Then I can query scroll position like this:
The code above works for me, but this may be not the best approach. Please correct/guide me, if I'm doing it in the wrong way.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions