Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

dropdown search field in react native


// npm install --save react-native-searchable-dropdown
import React, { Component, Fragment } from 'react';
import SearchableDropdown from 'react-native-searchable-dropdown';

var items = [
  {
    id: 1,
    name: 'JavaScript',
  },
  {
    id: 2,
    name: 'Java',
  },
  {
    id: 3,
    name: 'Ruby',
  },
  {
    id: 4,
    name: 'React Native',
  },
  {
    id: 5,
    name: 'PHP',
  },
  {
    id: 6,
    name: 'Python',
  },
  {
    id: 7,
    name: 'Go',
  },
  {
    id: 8,
    name: 'Swift',
  },
];
class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedItems: [
        {
          id: 7,
          name: 'Go',
        },
        {
          id: 8,
          name: 'Swift',
        }
      ]
    }
  }
  render() {
  return (
        <Fragment>
          {/* Multi */}
          <SearchableDropdown
            multi={true}
            selectedItems={this.state.selectedItems}
            onItemSelect={(item) => {
              const items = this.state.selectedItems;
              items.push(item)
              this.setState({ selectedItems: items });
            }}
            containerStyle={{ padding: 5 }}
            onRemoveItem={(item, index) => {
              const items = this.state.selectedItems.filter((sitem) => sitem.id !== item.id);
              this.setState({ selectedItems: items });
            }}
            itemStyle={{
              padding: 10,
              marginTop: 2,
              backgroundColor: '#ddd',
              borderColor: '#bbb',
              borderWidth: 1,
              borderRadius: 5,
            }}
            itemTextStyle={{ color: '#222' }}
            itemsContainerStyle={{ maxHeight: 140 }}
            items={items}
            defaultIndex={2}
            chip={true}
            resetValue={false}
            textInputProps={
              {
                placeholder: "placeholder",
                underlineColorAndroid: "transparent",
                style: {
                    padding: 12,
                    borderWidth: 1,
                    borderColor: '#ccc',
                    borderRadius: 5,
                },
                onTextChange: text => alert(text)
              }
            }
            listProps={
              {
                nestedScrollEnabled: true,
              }
            }
          />
          {/* Single */}
          <SearchableDropdown
            onItemSelect={(item) => {
              const items = this.state.selectedItems;
              items.push(item)
              this.setState({ selectedItems: items });
            }}
            containerStyle={{ padding: 5 }}
            onRemoveItem={(item, index) => {
              const items = this.state.selectedItems.filter((sitem) => sitem.id !== item.id);
              this.setState({ selectedItems: items });
            }}
            itemStyle={{
              padding: 10,
              marginTop: 2,
              backgroundColor: '#ddd',
              borderColor: '#bbb',
              borderWidth: 1,
              borderRadius: 5,
            }}
            itemTextStyle={{ color: '#222' }}
            itemsContainerStyle={{ maxHeight: 140 }}
            items={items}
            defaultIndex={2}
            resetValue={false}
            textInputProps={
              {
                placeholder: "placeholder",
                underlineColorAndroid: "transparent",
                style: {
                    padding: 12,
                    borderWidth: 1,
                    borderColor: '#ccc',
                    borderRadius: 5,
                },
                onTextChange: text => alert(text)
              }
            }
            listProps={
              {
                nestedScrollEnabled: true,
              }
            }
        />
      </Fragment>
  );
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript detect scroll wheel 
Javascript :: export default react 
Javascript :: exec reges 
Javascript :: capitalize first letter 
Javascript :: jquery each hover 
Javascript :: unshift method in javascript 
Javascript :: useisfocused react navigation 
Javascript :: React 18 to 17 
Javascript :: parse data from url javascript 
Javascript :: angular formgroup on value change 
Javascript :: javascript bitwise operators 
Javascript :: js numbers only string 
Javascript :: make a file downloadable in react 
Javascript :: ordering array 
Javascript :: how to import a json string from a file in typescript 
Javascript :: jquery ui dialog position fixed center 
Javascript :: Error: A Route is only ever to be used as the child of element, never rendered directly. Please wrap your Route in a Route 
Javascript :: react select disable option 
Javascript :: javascript collision detection 
Javascript :: google recaptcha reload 
Javascript :: javascript The replace() method 
Javascript :: how to initialize empty javascript object 
Javascript :: jquery checkbox group selected value 
Javascript :: print first n prime numbers in javascript 
Javascript :: palindrome number in javascript 
Javascript :: nodejs: http:send HTML to the Browser 
Javascript :: password validation in regex 
Javascript :: &ldquo;javascript remove last element from array 
Javascript :: discord js remove reaction from user 
Javascript :: javascript console.table 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =