Skip to content

Commit

Permalink
fix: fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hoaphantn7604 committed Oct 11, 2024
1 parent 7542ab2 commit f3eed81
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ yarn add react-native-element-dropdown
| searchQuery | (keyword: string, labelValue: string) => Boolean| No | Callback used to filter the list of items |
| inputSearchStyle | ViewStyle | No | Styling for input search |
| searchPlaceholder | String | No | The string that will be rendered before text input has been entered |
| searchPlaceholderTextColor | String | No | The text color of the placeholder string |
| renderInputSearch | (onSearch: (text:string) => void) => JSX.Element| No | Customize TextInput search |
| disable | Boolean | No | Specifies the disabled state of the Dropdown |
| dropdownPosition | 'auto' or 'top' or 'bottom' | No | Dropdown list position. Default is 'auto' |
Expand Down Expand Up @@ -125,6 +126,7 @@ yarn add react-native-element-dropdown
| searchQuery | (keyword: string, labelValue: string) => Boolean | No | Callback used to filter the list of items |
| inputSearchStyle | ViewStyle | No | Styling for input search |
| searchPlaceholder | String | No | The string that will be rendered before text input has been entered |
| searchPlaceholderTextColor | String | No | The text color of the placeholder string |
| renderInputSearch | (onSearch: (text:string) => void) => JSX.Element | No | Customize TextInput search |
| disable | Boolean | No | Specifies the disabled state of the Dropdown |
| dropdownPosition | 'auto' or 'top' or 'bottom' | No | Dropdown list position. Default is 'auto' |
Expand Down
2 changes: 1 addition & 1 deletion example/src/dropdown/Dropdown1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const DropdownComponent = () => {
inputSearchStyle={styles.inputSearchStyle}
iconStyle={styles.iconStyle}
data={data}
excludeSearchItems={excludeItem}
excludeItems={excludeItem}
autoScroll
search
maxHeight={300}
Expand Down
20 changes: 16 additions & 4 deletions example/src/dropdown/MultiSelectAll.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useRef, useState } from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { MultiSelect } from 'react-native-element-dropdown';
import { Button, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { IMultiSelectRef, MultiSelect } from 'react-native-element-dropdown';

const data = [
{ label: 'Item 1', value: '1' },
Expand All @@ -20,7 +20,7 @@ const excludeItem = [

const MultiSelectComponent = () => {
const [selected, setSelected] = useState<string[]>([]);
const ref = useRef(null);
const ref = useRef<IMultiSelectRef>(null);

const onSelectAll = (isSelectAll = true) => {
const selectItem: string[] = [];
Expand Down Expand Up @@ -71,15 +71,24 @@ const MultiSelectComponent = () => {
selectedStyle={styles.selectedStyle}
flatListProps={{ ListHeaderComponent: renderSelectAllIcon }}
/>
<View style={styles.button}>
<Button
title="Open"
onPress={() => {
ref.current?.open();
}}
/>
</View>
</View>
);
};

export default MultiSelectComponent;

const styles = StyleSheet.create({
container: { padding: 16 },
container: { padding: 16, flexDirection: 'row' },
dropdown: {
flex: 1,
backgroundColor: 'transparent',
borderBottomColor: 'gray',
borderBottomWidth: 0.5,
Expand Down Expand Up @@ -109,4 +118,7 @@ const styles = StyleSheet.create({
txtSelectAll: {
color: 'blue',
},
button: {
marginHorizontal: 16,
},
});
20 changes: 15 additions & 5 deletions src/components/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const DropdownComponent: <T>(
fontFamily,
iconColor = 'gray',
searchPlaceholder,
searchPlaceholderTextColor = 'gray',
placeholder = 'Select item',
search = false,
maxHeight = 340,
Expand Down Expand Up @@ -148,8 +149,11 @@ const DropdownComponent: <T>(
);

useEffect(() => {
const filterData = excludeData(data);
setListData([...filterData]);
if (data && searchText.length === 0) {
const filterData = excludeData(data);
setListData([...filterData]);
}

if (searchText) {
onSearch(searchText);
}
Expand All @@ -158,6 +162,7 @@ const DropdownComponent: <T>(

const eventOpen = () => {
if (!disable) {
_measure();
setVisible(true);
if (onFocus) {
onFocus();
Expand Down Expand Up @@ -316,8 +321,11 @@ const DropdownComponent: <T>(

_measure();
setVisible(visibleStatus);
const filterData = excludeData(data);
setListData(filterData);

if (data) {
const filterData = excludeData(data);
setListData(filterData);
}

if (visibleStatus) {
if (onFocus) {
Expand Down Expand Up @@ -560,7 +568,8 @@ const DropdownComponent: <T>(
}
onSearch(e);
}}
placeholderTextColor="gray"
placeholderTextColor={searchPlaceholderTextColor}
showIcon
iconStyle={[{ tintColor: iconColor }, iconStyle]}
/>
);
Expand All @@ -578,6 +587,7 @@ const DropdownComponent: <T>(
renderInputSearch,
search,
searchPlaceholder,
searchPlaceholderTextColor,
testID,
searchText,
]);
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 @@ -42,6 +42,7 @@ export interface DropdownProps<T> {
searchField?: keyof T;
search?: boolean;
searchPlaceholder?: string;
searchPlaceholderTextColor?: string;
disable?: boolean;
autoScroll?: boolean;
showsVerticalScrollIndicator?: boolean;
Expand Down
19 changes: 14 additions & 5 deletions src/components/MultiSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const MultiSelectComponent: <T>(
iconColor = 'gray',
inputSearchStyle,
searchPlaceholder,
searchPlaceholderTextColor = 'gray',
placeholder = 'Select item',
search = false,
maxHeight = 340,
Expand Down Expand Up @@ -149,8 +150,10 @@ const MultiSelectComponent: <T>(
);

useEffect(() => {
const filterData = excludeData(data);
setListData([...filterData]);
if (data && searchText.length === 0) {
const filterData = excludeData(data);
setListData([...filterData]);
}

if (searchText) {
onSearch(searchText);
Expand All @@ -160,6 +163,7 @@ const MultiSelectComponent: <T>(

const eventOpen = () => {
if (!disable) {
_measure();
setVisible(true);
if (onFocus) {
onFocus();
Expand Down Expand Up @@ -269,8 +273,11 @@ const MultiSelectComponent: <T>(

_measure();
setVisible(visibleStatus);
const filterData = excludeData(data);
setListData(filterData);

if (data) {
const filterData = excludeData(data);
setListData(filterData);
}

if (visibleStatus) {
if (onFocus) {
Expand Down Expand Up @@ -536,7 +543,8 @@ const MultiSelectComponent: <T>(
}
onSearch(e);
}}
placeholderTextColor="gray"
showIcon
placeholderTextColor={searchPlaceholderTextColor}
iconStyle={[{ tintColor: iconColor }, iconStyle]}
/>
);
Expand All @@ -554,6 +562,7 @@ const MultiSelectComponent: <T>(
renderInputSearch,
search,
searchPlaceholder,
searchPlaceholderTextColor,
testID,
]);

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 @@ -46,6 +46,7 @@ export interface MultiSelectProps<T> {
disable?: boolean;
showsVerticalScrollIndicator?: boolean;
searchPlaceholder?: string;
searchPlaceholderTextColor?: string;
dropdownPosition?: 'auto' | 'top' | 'bottom';
flatListProps?: Omit<FlatListProps<any>, 'renderItem' | 'data'>;
alwaysRenderSelectedItem?: boolean;
Expand Down

0 comments on commit f3eed81

Please sign in to comment.