Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to add custom item if search not found #79

Closed
sagarkbluebenz opened this issue May 18, 2022 · 6 comments
Closed

Want to add custom item if search not found #79

sagarkbluebenz opened this issue May 18, 2022 · 6 comments

Comments

@sagarkbluebenz
Copy link

sagarkbluebenz commented May 18, 2022

Hi im rendering a list .. if user search the list and he doesn't find the item.. then he can add that custom item.. is it possible?

@hoaphantn7604
Copy link
Owner

hoaphantn7604 commented May 24, 2022

hi @sagarkbluebenz ,
Please refer code example:

import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Dropdown } from 'react-native-element-dropdown';
import AntDesign from 'react-native-vector-icons/AntDesign';

const data = [
  { label: 'Item 1', value: '1' },
  { label: 'Item 2', value: '2' },
  { label: 'Item 3', value: '3' },
  { label: 'Item 4', value: '4' },
  { label: 'Item 5', value: '5' },
  { label: 'Item 6', value: '6' },
  { label: 'Item 7', value: '7' },
  { label: 'Item 8', value: '8' },
];

const DropdownComponent = () => {
  const [value, setValue] = useState(null);

  const renderEmptyList = () => {
    return (
      <View style={styles.emptyContainer}>
        <Text>List is empty!</Text>
      </View>
    );
  };

  return (
    <Dropdown
      style={styles.dropdown}
      placeholderStyle={styles.placeholderStyle}
      selectedTextStyle={styles.selectedTextStyle}
      inputSearchStyle={styles.inputSearchStyle}
      iconStyle={styles.iconStyle}
      data={data}
      search
      maxHeight={200}
      labelField="label"
      valueField="value"
      placeholder="Select item"
      searchPlaceholder="Search..."
      value={value}
      onChange={item => {
        setValue(item.value);
      }}
      renderLeftIcon={() => <AntDesign style={styles.icon} color="black" name="Safety" size={20} />}
      flatListProps={{ ListEmptyComponent: () => renderEmptyList() }}
    />
  );
};

export default DropdownComponent;

const styles = StyleSheet.create({
  dropdown: {
    marginTop: 360,
    height: 50,
    borderBottomColor: 'gray',
    borderBottomWidth: 0.5,
  },
  icon: {
    marginRight: 5,
  },
  placeholderStyle: {
    fontSize: 16,
  },
  selectedTextStyle: {
    fontSize: 16,
  },
  iconStyle: {
    width: 20,
    height: 20,
  },
  inputSearchStyle: {
    height: 40,
    fontSize: 16,
  },
  emptyContainer: {
    height: 50,
    margin: 12,
    alignItems: 'center',
    justifyContent: 'center',
  },
});

@sagarkbluebenz
Copy link
Author

Still Cannot add. Only showing List is empty...

@glaucomp
Copy link

Same issue

@developer8530
Copy link

text showing in reverse when dropdownPosition="top" selected
1675320519967

@hoaphantn7604
Copy link
Owner

text showing in reverse when dropdownPosition="top" selected 1675320519967

Hi @developer8530 , Install later version 2.7.0. Use inverted set is "false".

   <Dropdown
      {...}
      inverted={flase}
   />

@sadman11
Copy link

sadman11 commented Jul 6, 2023

did anyone manage to achieve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants