adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.64k stars 1.09k forks source link

[UseAsyncList] Support automatic client-side sorting after initial load #3959

Open GrantRussell opened 1 year ago

GrantRussell commented 1 year ago

πŸ™‹ Feature Request

On initial load, it would be nice if the sort option in useAsyncList was automatically called if the initialSortDescriptor option is also provided.

Alternatively, if this is not possible, it would be nice to update the doc page for useAsyncList to explicitly show that the user is responsible for managing the sort. The current documentation gives the impression that client-side sorting will be applied after implementing the provided code example, when in reality the final step is to manually call the sort option.

πŸ€” Expected Behavior

When passing a sort and initialSortDescriptor option, useAsyncList would automatically call the passed sort option upon resolving the initial async load.

😯 Current Behavior

Currently, the user is responsible for managing when the first client-side sort is applied, even though the expectation would be to apply the sort automatically especially if an initialSortDescriptor is also provided.

πŸ’ Possible Solution

See Expected Behavior

πŸ”¦ Context

After reading examples in the documentation of useAsyncList, it gives the impression that client-side sorting will be applied after supplying the sort option to useAsyncList. This doesn't seem to be the case, but the docs also don't offer any suggestions on how to apply that first sort.

πŸ’» Examples

https://codesandbox.io/s/listview-with-useasynclist-4cozi2?file=/src/App.js

🧒 Your Company/Team

Adobe Assets Essentials

🎁 Tracking Ticket (optional)

LFDanLu commented 1 year ago

Discussed with the team further. We'll want to update the docs here to be clear about how to perform sorting here since we don't know what exactly the user provided sort function will do (it might be server side and we'd want to avoid firing another network request).

Spriithy commented 9 months ago

Hi there ! Bumping this issue as this was effectively not straightforward behavior...

steveoh commented 3 months ago

This caught me off guard as well. I'd love some recommendations on how to have the list use my sort function on load on the client only.