Git Product home page Git Product logo

react-native-dropdown-select-list's Introduction

NPM VERSION NPM WEEKLY DOWNLOADS GITHUB STAR YOUTUBE VIEWS NPM LIFETIME DOWNLOADS

⭐ React Native Dropdown Select List

React Native Select List Equivalent to Html's Select "

Multiple Select List Select List


Light weight and Easy to use dropdown select list.

  • Style it your way with style props of every view.
  • Smooth performance on all platforms IOS, Android and Web.
  • Change Font Family Easily which community picker lacks.
  • Zero dependencies

Compatibility


iOS Android Web Expo

🔌 Installation

$ npm install react-native-dropdown-select-list

OR

$ yarn add react-native-dropdown-select-list

😎 Basic Usage for SelectList

import { SelectList } from 'react-native-dropdown-select-list'

const App = () => {

  const [selected, setSelected] = React.useState("");
  
  const data = [
      {key:'1', value:'Mobiles', disabled:true},
      {key:'2', value:'Appliances'},
      {key:'3', value:'Cameras'},
      {key:'4', value:'Computers', disabled:true},
      {key:'5', value:'Vegetables'},
      {key:'6', value:'Diary Products'},
      {key:'7', value:'Drinks'},
  ]

  return(
    <SelectList 
        setSelected={(val) => setSelected(val)} 
        data={data} 
        save="value"
    />
  )

};

😎 Basic Usage for MultipleSelectList

import { MultipleSelectList } from 'react-native-dropdown-select-list'

const App = () => {

  const [selected, setSelected] = React.useState([]);
  
  const data = [
      {key:'1', value:'Mobiles', disabled:true},
      {key:'2', value:'Appliances'},
      {key:'3', value:'Cameras'},
      {key:'4', value:'Computers', disabled:true},
      {key:'5', value:'Vegetables'},
      {key:'6', value:'Diary Products'},
      {key:'7', value:'Drinks'},
  ]

  return(
    <MultipleSelectList 
        setSelected={(val) => setSelected(val)} 
        data={data} 
        save="value"
        onSelect={() => alert(selected)} 
        label="Categories"
    />
  )

};

For Live Demo (Expo Snack)


🔧 General Props

Applicable on both SelectList & MultipleSelectList Components

Name Type Description
save string Pass ('key' or 'value') to save data of your choice in your local state variable
onSelect Function Pass any function that you want to trigger immediately after a value is selected
placeholder String Placeholder text that will be displayed in the select box
search boolean set to false if you dont want to use search functionality
maxHeight Number Maximum height of the dropdown wrapper to occupy
data array or array[object] Data which will be iterated as options of select list
setSelected Function For Setting the option value which will be stored in your local state
searchicon JSX Element Pass any JSX to this prop like Text, Image or Icon to show instead of search icon
arrowicon JSX Element Pass any JSX to this prop like Text, Image or Icon to show instead of chevron icon
closeicon JSX Element Pass any JSX to this prop like Text, Image or Icon to show instead of close icon
searchPlaceholder String Custom placeholder text for search TextInput
defaultOption Object Pass default selected option in key value pair
fontFamily string Pass font name to apply globally on each text field of component
notFoundText string Pass your custom message if any search result returns empty
dropdownShown boolean Control your dropdown ( on & off ) state by changing its value to true or false

🔧 General Style Props

Applicable on both SelectList & MultipleSelectList Components

Name Type Description
boxStyles Object Additional styles for select box parent wrapper
inputStyles Object Additional styles for text of selection box
dropdownStyles Object Additional styles for dropdown scrollview
dropdownItemStyles Object Additional styles for dropdown single list item
dropdownTextStyles Object Additional styles for dropdown list items text
disabledItemStyles Object Additional styles for disabled dropdown list item
disabledTextStyles Object Additional styles for disabled dropdown list items text

😎 Advanced Usage

import { SelectList } from 'react-native-dropdown-select-list'

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(
    <SelectList 
      onSelect={() => alert(selected)}
      setSelected={setSelected} 
      fontFamily='lato'
      data={data}  
      arrowicon={<FontAwesome name="chevron-down" size={12} color={'black'} />} 
      searchicon={<FontAwesome name="search" size={12} color={'black'} />} 
      search={false} 
      boxStyles={{borderRadius:0}} //override default styles
      defaultOption={{ key:'1', value:'Jammu & Kashmir' }}   //default selected option
    />
  )

};

😎 Getting Options From Database

import { SelectList } from 'react-native-dropdown-select-list'

const App = () => {

  const [selected, setSelected] = React.useState("");
  const [data,setData] = React.useState([]);
  
  React.useEffect(() => 
    //Get Values from database
    axios.get('https://jsonplaceholder.typicode.com/users')
      .then((response) => {
        // Store Values in Temporary Array
        let newArray = response.data.map((item) => {
          return {key: item.id, value: item.name}
        })
        //Set Data Variable
        setData(newArray)
      })
      .catch((e) => {
        console.log(e)
      })
  ,[])

  return(
    <SelectList setSelected={setSelected} data={data} onSelect={() => alert(selected)} />
  )

};

🔧 Additional Props

Applicable on MultipleSelectList Only

Name Type Description
label string Pass any string to be placed instead of default label

🔧 Additional Style Props

Applicable on MultipleSelectList Only

Name Type Description
disabledCheckBoxStyles Object Additional styles disabled checkbox inside dropdown
checkBoxStyles Object Additional styles for active checkbox
badgeStyles Object Additional styles for badges of selected values
badgeTextStyles Object Additional styles for Text of badges of selected values
labelStyles Object Additional styles for label of multiple select list

▶️ Watch Video

Watch the video


💲 Would you like to support me?

If you would like me come up with similar packages, buy me a cup of coffee to boost my energy.

Paypal

For Live Demo (Expo Snack)


react-native-dropdown-select-list's People

Contributors

adrian-jas avatar danish1658 avatar mmusaib avatar westerandr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-native-dropdown-select-list's Issues

Reset to empty select option

Hi there,

i'll try to explain the issue i'm facing at the moment.
I'm using the Select list in this way:

<SelectList data={dropDownBuyableGiftCards} setSelected={(id: string) => selectGiftCardAmountHandler(id)} placeholder="Scegli il valore" search={false} boxStyles={styles.dropdown} inputStyles={styles.dropdownText} dropdownStyles={styles.dropdownItemsContainer} dropdownTextStyles={styles.dropdownText} defaultOption={{ key: null, value: null }} />

where selectGiftCardAmountHandler it's a function that dispatch a action to a reducer:

const selectGiftCardAmountHandler = (id: string) => { const giftCardToBuy = buyableGiftCards.find((buyableGiftCard) => buyableGiftCard.id === id); dispatch(addGiftCardAmountToBuy({ id: giftCardToBuy.id, amount: giftCardToBuy.voucher.gift.amount })); };

Everything looks good, after the purchase of the gift card mentioned in my code i will go back to my home page and then if i go back to the gift card section the previous values are still selected BUT if i go back again and enter the gift card again the values will reset.

Looks like needs 2 re render to reset. I also have a:
useEffect(() => { (async () => { const buyableGiftCards = await getBuyableGiftCards(); dispatch(addBuyableGiftCards(buyableGiftCards)); })(); dispatch(resetGiftCardToBuy()); }, [giftcardToBuy]);

where resetGiftCardToBuy reset all my data selected but i don't think this will help.

Anyone could help please

Search Placeholder Text

There is no prop for the search placeholder. I have added that support for the package. Please accept my pull request

Add disable Input option

Hello,

I think is simple add a disable option, that will be so interesting to much cases.

Reciving a "editable" parameter and passing that to the TextInput, how would be in a normal TextInput, and making it impossible the "onPress" on TouchableOpacity in this cases.

I got no execute the project in my machine to try this feature, but a realy think will be simple change.

Sorry for speculation, but a realy liked this project, success!

Tell me if you will want any help. I don't know a lot, but I would love to help!

How to show Default value on DropList

Is it a way to show the Default value or the previously selected value when I open the drop list?
For example I made a year picker from 2002 - 2072 and I set defaultOption={current_year}. The current year shows properly by default, but when I open the drop list it shows year 2002 first (the beginning of my list). Is it possible to show my default year?
droplist

How to tell if dropdown is expanded or not

I have some other components on the screen that will need to react to the dropdown opening. Is there a function that can be run when the dropdown opens or something similar?

Search results persist after pressing the 'x'

When conducting a search, either the list will be filtered to contain less results are no results at all. When the 'x' is pressed it closes the dropdown and clears the search term but does not reset the list items being shown. This could be quite confusing to a user.
A user has to start typing again and backspace all the characters to see all the list items again.

Add Keyboard.dismiss() option

I'm using your excellent dropdown select (thank you!) as part of a wider form and would love it if I were able to dismiss the open keyboard on pressing the dropdown.

For example, if I've just entered something in a TextInput on the form and then want to select from this element, upon the dropdown opening the keyboard remains open and the first time I try and select an option from the dropdown, that dismisses the keyboard and doesn't actually select the option, I then have to select it again.

I tried to circumvent the need to add it to this repo by wrapping the element with a Touchable that has an onPress of Keyboard.dismiss() but that isn't working. It also doesn't work when wrapping the entire element in a pre-defined HideKeyboard function as suggested here, though this does close the keyboard if you tap anywhere else except the component.

Unless there's another way to do it?

I'm using React-Native with Expo and currently seeing this behaviour on Android. I don't have the means to test it on iPhone at the moment.

I hacked together a little work around by modifying the index.tsx file:

Importing Keyboard on line 2
Adding Keyboard.dismiss() to the onPress function on line 215

Happy to submit this as a PR if you think always automatically closing the keyboard is of value, but the alternative is I thought you might want to add it as a customisable boolean option and my skills aren't at that level yet!

Dropdown list is blocked

Hi
The list is locked until I click on an item in the list. Shouldn't the drop-down menu just close again if I click on a part of the screen?

Thanks

Feature Request

Please provide any function to dismiss dropdown without selecting any value in dropdown list item.

Example : like chevron up icon shown instead chevron down icon on right side of the container to dismiss the dropdown after dropdown list toggle.

defaultOptions set to Optional?

Hi there,

when I installed the package, it seemed the defaultOptions feature was mandatory, unlike what is used in the docs/readme.

I went ahead and edited it myself in my code, but just to make sure if it should be optional or not in your package?

How to reset to unselected

I have two select-lists. The second is populated depending on the selection in the first.

How do I clear the selection of the second list when the selection of the first list is changed? Setting defaultOption to undefined does not clear the selection.

Disable dropdown.

If user need to disable click on dropdown then ?

in item it is working but what if user need to disable dropdown click for a while or use a state to disable or not.

Error on use component

None of these files exist:

  • search.png
  • node_modules\react-native-dropdown-select-list\assets\images\search.png\index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
    180 | ?
    181 | <Image

182 | source={require('./assets/images/search.png')}
| ^
183 | resizeMode='contain'
184 | style={{width:20,height:20,marginRight:7}}
185 | />

Can't close dropdown

I can't seem to close dropdown after search is set to true without selecting an object

Unable to provide a custom close icon

Currently you can provide custom JSX elements for the search icon and the dropdown arrow icon, it would be great if you could also provide a custom element for the close icon that shows when the dropdown is open.

How to set a particular value to drop down when the view is loaded ?

Hi. This is my code

<SelectList 
     search = {false}
     setSelected={(value) => {setSelected(value);}} 
   data={[
                      {
                        key: '1',
                        value: StringsOfLanguages.male,
                      },
                      {
                        key: '2',
                        value: StringsOfLanguages.female,
                      },
                      {
                        key: '3',
                        value: StringsOfLanguages.unspecified,
                      },]
      } 
    // save="value"
    defaultOption = {{key:'1',value:StringsOfLanguages.male}}
/>

I have given defaultOption. But still the item which was selected when the view was previously loaded is showing be default.

How to setSelected = key

Hi,

I have been having some troubles implementing the setSelected method to save the selected key. All I can manage to do is save the value.

My data array looks like the following:

[{ key: "1", value: "name"}, { key: "2", value: "name2"}]

<SelectList
          setSelected={(key) => {
            console.log(key);
            setSelectedBoatId(key);
          }}
          data={data}
          save="value"
          defaultOption={data[0]}
        />

Here I want the setSelectedBoatId to take in the number held in the object key but all I seem to be able to get is the value. If anyone can help out would be greatly appreciated! 🚀

No prop to set defaultOption of SelectList

This is important to have for the SelectList component, especially if state is being managed. We need the ability to allow the currently selected option to persist between renders.

Wrong Types for Text Component

Hi,

looks like that a ViewStyle Props is assigned to text props like inputStyles, dropdownStyles.
Text styles cannot be applied to View Styles so for example fontSize is not accessible, won't do anything and return typescript error

Element type is invalid: expected a string

I was trying to render this in Formik but was recieving the same error, then I tried to create a separate Formarea but still getting the same error and lastly I removed all the code from screen and the page still shows the error but works when SelecList is commented out. Please chek this error.

**Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got:
undefined. You likely forgot to export your
component from the file it's defined in, or
you might have mixed up default and named imports.

Check the render method of Signup.**

@danish1658

import React, { useState } from "react"
import { StatusBar } from 'expo-status-bar';
import { SelectList } from "react-native-dropdown-select-list";
import KeyboardAvoidingWrapper from "../components/KeyboardAvoidingWrapper.js";
import { StyledContainer, InnerContainer, PageTitle, StyledFormArea } from "../components/styles.js"
const Signup = ({ navigation }) => {
    const [selected, setSelected] = useState("");
    const data = [
        { key: '1', value: 'My First Item' }
    ];
    return (
        <KeyboardAvoidingWrapper>
            <StyledContainer>
                <StatusBar style="dark" />
                <InnerContainer>
                    <PageTitle>Testing React Native Dropdown Select List</PageTitle>
                    <StyledFormArea>
                        {/* <SelectList data={data} setSelected={setSelected} /> */}
                    </StyledFormArea>
                </InnerContainer>
            </StyledContainer>
        </KeyboardAvoidingWrapper>
    )
}

export default Signup 

Error during search

When I am trying to search something, I am getting the following error.

undefined is not an object (evaluating 'item.value.toLowerCase')

SelectListOver Content / zIndex

Is there a way to have the SelectList display over content? When the SelectList is closed, the content below it is correctly placed. But when I select the SelectBox, the content below it scrolls down. Is there a way to display to dropdown over content, rather than moving it? I've tried setting the zIndex of the View container, using the style attribute, the dropdownStyles attribute etc. but not luck.

<SelectList 
  placeholder="Select a Category"
  setSelected={(val) => setCurrentCategoryId(val)} 
  data={gearCategories} 
  save="key"
  search={false}
  maxHeight="175"
  dropdownStyles={{ zIndex: 5}}
/>

setSelected is called on the initial mounting of component

Hello there,

When this component is initially mounted the setSelected function is executed. Is this how it is supposed to behave?

I believe the setSelected function should only execute whenever the user selects a new option from the dropdown since this function is currently the only way to get the selected value. Having it run on mount leads to some nasty bugs.

Thank you!

Change color of disabled items

Is there a way to set the color of the text on disabled rows? I would love to change the color of the text and the background of that row as well if possible.

JSX element type 'SelectList' does not have any construct or call signatures.

Hi there,

i'm trying to use this library in a react native expo project with typescript but when i use it everything its working fine but i'll get this "warning" on the SelectList component "JSX element type 'SelectList' does not have any construct or call signatures."

Then i notice that when i use the setSelected function only the key object will pass.

I have checked the node modules and looks there is something wrong:

  • on line 1 on index.tsx JSXElementConstructor is never used
  • on line 195 on index.ts item.value does not exist.

i hope you guys could fix this annoying issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.