Skip to content

Commit

Permalink
feat: able to add items you search for that are not in the list
Browse files Browse the repository at this point in the history
  • Loading branch information
jrammmy committed Apr 1, 2021
1 parent d82f3e1 commit 6210dea
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ export default class Dropdown extends PureComponent {
selected: -1,
modal: false,
value,
data: this.props.data
data: this.props.data,
searchText: undefined,
};
}

Expand Down Expand Up @@ -569,16 +570,15 @@ export default class Dropdown extends PureComponent {
);
}

searchFilterFunction(text) {
searchFilterFunction(searchText) {
let arrayholder = this.props.data
const newData = arrayholder.filter(item => {
const itemData = `${item.value.toUpperCase()}`;
const textData = text.toUpperCase();

const textData = searchText.toUpperCase();
return itemData.indexOf(textData) > -1;
});

this.setState({ data: newData });
newData.push({value: searchText});
this.setState({ data: newData, searchText });
};

renderItem({ item, index }) {
Expand Down Expand Up @@ -771,6 +771,10 @@ export default class Dropdown extends PureComponent {
style={styles.input}
placeholder={'Search here'}
placeholderTextColor="#808080"
clearButtonMode="always"
onSubmitEditing={() => {
this.setState({value: this.state.searchText, modal: false})
}}
onChangeText={text => this.searchFilterFunction(text)}
/>

Expand Down

0 comments on commit 6210dea

Please sign in to comment.