Skip to content

Commit

Permalink
feat: add props searchField
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoà Phan authored and Hoà Phan committed Mar 5, 2023
1 parent 796148e commit 7f97b25
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
17 changes: 9 additions & 8 deletions example/src/dropdown/Dropdown1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { StyleSheet, Text, View } from 'react-native';
import { Dropdown } from 'react-native-element-dropdown';

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' },
{ label: 'Item 1', value: '1', search: 'a' },
{ label: 'Item 2', value: '2', search: 'b' },
{ label: 'Item 3', value: '3', search: 'c' },
{ label: 'Item 4', value: '4', search: 'd' },
{ label: 'Item 5', value: '5', search: 'e' },
{ label: 'Item 6', value: '6', search: 'f' },
{ label: 'Item 7', value: '7', search: 'g' },
{ label: 'Item 8', value: '8', search: 'h' },
];

const DropdownComponent = () => {
Expand Down Expand Up @@ -44,6 +44,7 @@ const DropdownComponent = () => {
minHeight={100}
labelField="label"
valueField="value"
searchField="search"
placeholder={!isFocus ? 'Dropdown 1' : '...'}
searchPlaceholder="Search..."
value={value}
Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@
"files": [
"src",
"lib",
"android",
"ios",
"cpp",
"react-native-element-dropdown.podspec",
"!lib/typescript/example",
"!android/build",
"!ios/build",
"!**/__tests__",
"!**/__fixtures__",
"!**/__mocks__"
Expand Down
7 changes: 4 additions & 3 deletions src/components/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const DropdownComponent: <T>(
data = [],
labelField,
valueField,
searchField,
value,
activeColor = '#F6F7F8',
fontFamily,
Expand Down Expand Up @@ -296,7 +297,7 @@ const DropdownComponent: <T>(
(text: string) => {
if (text.length > 0) {
const defaultFilterFunction = (e: any) => {
const item = _.get(e, labelField)
const item = _.get(e, searchField || labelField)
?.toLowerCase()
.replace(' ', '')
.normalize('NFD')
Expand All @@ -311,7 +312,7 @@ const DropdownComponent: <T>(
};

const propSearchFunction = (e: any) => {
const labelText = _.get(e, labelField);
const labelText = _.get(e, searchField || labelField);

return searchQuery?.(text, labelText);
};
Expand All @@ -324,7 +325,7 @@ const DropdownComponent: <T>(
setListData(data);
}
},
[data, labelField, searchQuery]
[data, searchField, labelField, searchQuery]
);

const onSelect = useCallback(
Expand Down
1 change: 1 addition & 0 deletions src/components/Dropdown/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface DropdownProps<T> {
placeholder?: string;
labelField: string;
valueField: string;
searchField?: string;
search?: boolean;
searchPlaceholder?: string;
disable?: boolean;
Expand Down
7 changes: 4 additions & 3 deletions src/components/MultiSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const MultiSelectComponent: <T>(
style = {},
labelField,
valueField,
searchField,
selectedStyle,
selectedTextStyle,
itemContainerStyle,
Expand Down Expand Up @@ -262,7 +263,7 @@ const MultiSelectComponent: <T>(
(text: string) => {
if (text.length > 0) {
const defaultFilterFunction = (e: any) => {
const item = _.get(e, labelField)
const item = _.get(e, searchField || labelField)
?.toLowerCase()
.replace(' ', '')
.normalize('NFD')
Expand All @@ -277,7 +278,7 @@ const MultiSelectComponent: <T>(
};

const propSearchFunction = (e: any) => {
const labelText = _.get(e, labelField);
const labelText = _.get(e, searchField || labelField);

return searchQuery?.(text, labelText);
};
Expand All @@ -290,7 +291,7 @@ const MultiSelectComponent: <T>(
setListData(data);
}
},
[data, labelField, searchQuery]
[data, searchField, labelField, searchQuery]
);

const onSelect = useCallback(
Expand Down
1 change: 1 addition & 0 deletions src/components/MultiSelect/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface MultiSelectProps<T> {
placeholder?: string;
labelField: string;
valueField: string;
searchField?: string;
search?: boolean;
disable?: boolean;
showsVerticalScrollIndicator?: boolean;
Expand Down

0 comments on commit 7f97b25

Please sign in to comment.