-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Autocomplete] support pagination on Asynchronous requests #18450
Comments
@vadimka123 I'm not sure to understand the use case. From my perspective, pagination should not be necessary. Either you request the data incrementally and add them to the list of options, then once the list is fully loaded, you enable the search. Or you really have too much data and you opt for an instant search like call API, for each keystroke. What do you think? |
@oliviertassinari you can see example of this feature in select2 library react-select has Even ordinary callback would really help |
@vadimka123 Thanks for the link. Ok so if you have millions of options, you would need to perform a query per keystroke, similar to https://material-ui.com/components/autocomplete/#google-maps-place. What's your API like? |
@oliviertassinari, various CRMs like Salesforce, Pardot, Eloqua, Marketo Also I updated prev comment |
@vadimka123 Do you have an example of such API so we can have a look at how we can best handle it? |
@oliviertassinari |
@vadimka123 Ok, I see your point. You have an autocomplete like API that returns x results and you would like to allow users to scroll down the list of options instead of asking them to refine the query with something more specific that returns fewer results, below the pagination logic. If it's accurate, I would challenge the use case for it in the first place. Forcing users to refind the query might yield a better UX. It might not be very important to support. However, we can explore it further. They are multiple elements to uncover here:
|
So, if you provide a custom <Autocomplete
ListboxProps={{
onScroll: (event: React.SyntheticEvent) => {
const listboxNode = event.currentTarget;
if (listboxNode.scrollTop + listboxNode.clientHeight === listboxNode.scrollHeight) {
loadMoreResults()
}
}
}}
/> |
@oliviertassinari Callback when menu is scrolled. At this point you offer one option to implement this. It's great Also there is one big catch Per documentation you have loading state. It's can be used for add loading indicator as last option if exists other options? |
@vadimka123 Yeah, I'm not opposed to a
WAI-ARIA makes the Home and End key handling optional: https://www.w3.org/TR/wai-aria-practices/#combobox. Could you share more on what it can be problematic? I think that we can consider such an option.
I don't know. I guess yes? |
@oliviertassinari |
This comment has been minimized.
This comment has been minimized.
@oliviertassinari I'm not sure it's a great idea to only provide |
I'm still confused about the problem we are trying to solve here. So far, I have seen the following mentions:
In both cases, I believe the Autocomplete components don't need any changes. Is it accurate? What did I miss? To summarize, we are waiting for a compelling reason. Why would an end-user or a UX designer would want to implement this behavior? |
<Autocomplete
ListboxProps={{
onScroll: (event: React.SyntheticEvent) => {
const listboxNode = event.currentTarget;
if (listboxNode.scrollTop + listboxNode.clientHeight === listboxNode.scrollHeight) {
loadMoreResults()
}
}
}}
/> Hello Olivier, this has just been useful for me as well. Your solution was easy enough, however, I also think that adding this as a specific feature is not pointless at all. |
This comment has been minimized.
This comment has been minimized.
I'm adding the "good to take" label as it seems easy to implement. We could also consider a @DanailH has recently added a similar feature in the data grid component under mui/mui-x#1199. |
I also have a big amount of data that I need to fetch. So it would be good to have a prop that will load more data onScroll, to prevent delays. |
I also second the above comment. |
Hello! Is anyone working on this? This is really a useful feature. I achieved the pagination using react-window-infinite-loader with Autocomplete. |
I agree this would be a useful. I had implemented the solution offered previously but after migrating to v5, the items scroll back to top on loading more items. |
Hello! Have you maybe found a solution to keep the position of the scroll after loading more items? |
Hello everyone! |
I have an use case similar and autocomplete functionality is handled all on backend and listing is paginated so when user click it loads this request
and when user scroll to end on list
if user type anything on input it trigers another resquest
users are grouped by rule to it I can use I could use this workaround here Is there any idea how can I do it using this component? |
We are working on adding a Material UI:
Joy UI:
Let us know for any feedback! |
This comment was marked as duplicate.
This comment was marked as duplicate.
Good day, is there any update on this one? |
I think there is no update, i worked one day but did not find solution with mui tag |
This solution working for us Maybe close ? |
I'm using the same solution and it seems that it doesn't scroll the list to the very top after loading a new batch of results anymore 👍
|
i used following fix to work around the scrolling issue:
) in a useEffect I listen to this data and set the scroll to the old value:
if you can await your loadMoreResults() function i would recommend you not solving this over useEffect and useRefs, but await the loadMoreResults() and then scrollTo afterwards. (Note: make sure to store the scrollTop in a variable before calling your fetching function as it will get overwritte otherwise) |
Hello, any news? |
This solution works for me! ("@mui/material": "^5.15.1") |
Working sample. |
A solution for this can be to use
|
@arunmmanoharan thank you, but when I search for an item that is not on the initial loaded list, then this does not appear. How can we have both the "list" logic but also the "search" logic to work for the all the values of the backend table? |
Would be very nice to add any ability for support pagination on Asynchronous requests
Many resources have limitations on requests and we can not get all results at once
Also reading everything page by page can lead to exceed limit of requests and it will be too slow
We would likely need to extend the API:
Benchmark
The text was updated successfully, but these errors were encountered: