Skip to content

Commit 9905ae4

Browse files
committed
feat: able to add items you search for that are not in the list
1 parent d82f3e1 commit 9905ae4

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/components/dropdown/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ export default class Dropdown extends PureComponent {
186186
selected: -1,
187187
modal: false,
188188
value,
189-
data: this.props.data
189+
data: this.props.data,
190+
searchText,
190191
};
191192
}
192193

@@ -569,16 +570,15 @@ export default class Dropdown extends PureComponent {
569570
);
570571
}
571572

572-
searchFilterFunction(text) {
573+
searchFilterFunction(searchText) {
573574
let arrayholder = this.props.data
574575
const newData = arrayholder.filter(item => {
575576
const itemData = `${item.value.toUpperCase()}`;
576-
const textData = text.toUpperCase();
577-
577+
const textData = searchText.toUpperCase();
578578
return itemData.indexOf(textData) > -1;
579579
});
580-
581-
this.setState({ data: newData });
580+
newData.push({value: searchText});
581+
this.setState({ data: newData, searchText });
582582
};
583583

584584
renderItem({ item, index }) {
@@ -771,6 +771,10 @@ export default class Dropdown extends PureComponent {
771771
style={styles.input}
772772
placeholder={'Search here'}
773773
placeholderTextColor="#808080"
774+
clearButtonMode="always"
775+
onSubmitEditing={() => {
776+
this.setState({value: this.state.searchText, modal: false})
777+
}}
774778
onChangeText={text => this.searchFilterFunction(text)}
775779
/>
776780

0 commit comments

Comments
 (0)