-
I'm working on implementing infinite scroll for a Select component (with a Combobox from Mantine), where new data should be loaded when the user scrolls to the bottom of the dropdown list. However, I'm facing the following issues: onBottomReached is not being triggered correctly: When scrolling with a mouse wheel, the onBottomReached handler doesn't trigger as expected. It only works when I manually drag the scrollbar to the bottom. How can I fix this so the handler triggers when scrolling via mouse wheel as well? Offset tolerance for bottom detection: I want to add some tolerance to the onBottomReached detection. Instead of triggering only when the scroll is at the very bottom, I'd like to trigger it when the user is a few pixels away from the bottom. This would help provide a smoother infinite scroll experience. How can I do this effectively? Handling dynamic container height: The height of the dropdown (ScrollArea) may change dynamically depending on the content. However, I’m struggling to calculate the total scrollable height (scrollHeight) of the dropdown area after scrolling has occurred. I can get the height of the container (ScrollArea), but I can’t get the full scrollable height (i.e., including the scrolled content). How can I calculate this dynamically?
Key Problems:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Solved guys! Infinite scroll is a useful feature that allows for the seamless loading of data in a dropdown or list as the user scrolls down, rather than loading all the data upfront. This technique is especially helpful when dealing with large datasets or when wanting to improve the performance of an application by reducing initial loading times. In this article, we'll discuss how we can implement infinite scroll using Mantine's Combobox component, with a custom solution for triggering the onBottomReached event and handling dynamic heights. Problem Statement Triggering onBottomReached on Mouse Wheel Scroll: The handler for detecting when the user reaches the bottom of the dropdown doesn't trigger when using the mouse wheel, it only triggers when manually dragging the scrollbar to the bottom. Offset Tolerance for Bottom Detection: We want to trigger the infinite scroll action when the user is not exactly at the bottom of the dropdown but a few pixels above it. This provides a smoother and more intuitive experience. Handling Dynamic Container Height: Since the height of the dropdown may change dynamically based on its content, we need to calculate the total scrollable height (scrollHeight) accurately, including the scrolled content. Solution Overview
Code Snippet:
Full Code Implementation
Feel free to integrate this approach into your project, and let us know how it works for you! |
Beta Was this translation helpful? Give feedback.
Solved guys!
Infinite scroll is a useful feature that allows for the seamless loading of data in a dropdown or list as the user scrolls down, rather than loading all the data upfront. This technique is especially helpful when dealing with large datasets or when wanting to improve the performance of an application by reducing initial loading times. In this article, we'll discuss how we can implement infinite scroll using Mantine's Combobox component, with a custom solution for triggering the onBottomReached event and handling dynamic heights.
Problem Statement
The task at hand is to implement infinite scroll in the Combobox dropdown of Mantine. There are three main problems we want to addr…