danish1658 / react-native-dropdown-select-list

☝️ React Native Select List Equivalent to Html's Select with options"
https://www.npmjs.com/package/react-native-dropdown-select-list
MIT License
193 stars 90 forks source link

Added defaultOptions to Multi Select List #86

Open KoalaBear opened 11 months ago

KoalaBear commented 11 months ago

The current defaultOption exists on both MultipleSelectList and SelectList while it is only implemented for SelectList. So I added a defaultOptions variable & implemented it for MultipleSelectList in order to be able to load up a list of previously selected values from my app storage.

apolloid commented 11 months ago

I had raised a pull request to Koala's repo so as to make the defaultOptions work with save props ('key' or 'value') and also in a format similar to defaultOption in Select. Not sure whether want to keep it as defaultOption too in the MultiSelect instead of defaultOptions

const App = () => {

  const [selected, setSelected] = React.useState([]);

  const data = [
    {key:'1',value:'Jammu & Kashmir'},
    {key:'2',value:'Gujrat'},
    {key:'3',value:'Maharashtra'},
    {key:'4',value:'Goa'},
  ]

  return(
    <MultipleSelectList 
      onSelect={() => alert(selected)}
      setSelected={(val) => setSelected(val)} 
      data={data} 
      save="key"
      defaultOptions={[ {key:'1', value:'Jammu & Kashmir' }, {key:'4', value:'Goa' }]}   //default selected options
    />
  )

};
bohnerjosh commented 6 months ago

As KoalaBear mentioned, I saw that MultipleSelectList has a defaultOptions property, but it is not implemented. I am working on an app right now where this functionality would be very helpful. Please get this reviewed and merge soon. Thanks.

dayoherrera commented 1 month ago

Hello, I have been using the library and it would be great to have the functionality of sending the default values ​​to the MultiSelectList. Could you please continue with this PR? Thank you @danish1658