miljodir / md-components

Design-komponenter for Miljødirektoratet (CSS og React)
https://miljodir.github.io/md-components
MIT License
3 stars 2 forks source link

RB-2548: Skjemakomponent med async lasting av valg #19

Closed vstenvik closed 7 months ago

vstenvik commented 1 year ago

Describe your changes

I have added a new component, AutocompleteAsync, that builds on top of the existing component Autocomplete. The pre-existing Autocomplete only supports only initial load and setting of the options for the dropdown and filters through that list. Providing it with a function with a Promise is not supported. However, this new component loads the options/result list on demand. Taking in an async function that returns a Promise which is called every time the text in the input field is changed. This is useful for dynamic loading of lists and where the lists are very long.

I also added the ability to set the input field to required and to show both the value and the text.

A known bug in the story example is that is you choose an option and move to another tab and then back it will swap the visible text in the input field from the text to the value. I have tried to retrieve the options list in useEffect(()=>{}, []) but for some reason it returns options as nothing. I have tested the component in my own system and have not experienced the same issue.

Checklist before requesting a review

Picture of the new component: image

turiddahl commented 7 months ago

Konkludert med at dette er bedre å løse med en wrapper for MdAutocomplete som lages i spesifikt prosjekt. Det vil dermed ikke bli lagt til en egen komponent for det i designsystemet. Lukker derfor denne PRen