PaackEng / elm-ui-dropdown

Dropdown module for Elm UI
https://package.elm-lang.org/packages/PaackEng/elm-ui-dropdown/latest/
MIT License
20 stars 11 forks source link

Support for loading and searching dropdown items via ajax #36

Open aszenz opened 3 years ago

aszenz commented 3 years ago

Thanks for creating this package.

I would like to know if there's a way to load items lazily via ajax requests, we have drop-downs with hundreds of items that cannot be preloaded.

On a related note it would be great if searching could also be done via ajax requests.

The best example of this currently is jQuery based select2 and react based react-select.

PedroHLC commented 3 years ago

I would like to know if there's a way to load items lazily via ajax requests

You can use anything that can transform into an array of objects, but I would recommend showing a spinner when loading the data, approaching a state-machine like this: http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html

If searching could also be done via ajax requests.

Right now search is done by filtering locally, we can accept that as a feature if someone is interested in submitting a PR.

EDIT: For reference: https://package.elm-lang.org/packages/PaackEng/elm-ui-dropdown/latest/Dropdown#filterable

aszenz commented 3 years ago

You can use anything that can transform into an array of objects, but I would recommend showing a spinner when loading the data, approaching a state-machine like this: http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html

So when it's a big drop down list I can't get an array of objects all at once, ideally i would load 10 options, show them when the user opens the drop down and then once the user scrolls past these 10 options, load 10 more and so on. This will require a paginated api, to which the drop down can send commands to. Similarly filtering would work based on an api.

Admittedly this is a complex requirement but it's been implemented before in elm by https://github.com/MadonnaMat/elm-select-two