react-native-input-select 1.1.7 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +3 -2
  2. package/lib/commonjs/components/CheckBox/index.js +1 -1
  3. package/lib/commonjs/components/CheckBox/index.js.map +1 -1
  4. package/lib/commonjs/components/Dropdown/DropdownFlatList.js +4 -2
  5. package/lib/commonjs/components/Dropdown/DropdownFlatList.js.map +1 -1
  6. package/lib/commonjs/components/Dropdown/DropdownSectionList.js +5 -3
  7. package/lib/commonjs/components/Dropdown/DropdownSectionList.js.map +1 -1
  8. package/lib/commonjs/components/Input/index.js +0 -2
  9. package/lib/commonjs/components/Input/index.js.map +1 -1
  10. package/lib/commonjs/index.js +19 -20
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/utils/index.js +1 -1
  13. package/lib/commonjs/utils/index.js.map +1 -1
  14. package/lib/module/components/CheckBox/index.js +1 -1
  15. package/lib/module/components/CheckBox/index.js.map +1 -1
  16. package/lib/module/components/Dropdown/DropdownFlatList.js +4 -2
  17. package/lib/module/components/Dropdown/DropdownFlatList.js.map +1 -1
  18. package/lib/module/components/Dropdown/DropdownSectionList.js +5 -3
  19. package/lib/module/components/Dropdown/DropdownSectionList.js.map +1 -1
  20. package/lib/module/components/Input/index.js +0 -2
  21. package/lib/module/components/Input/index.js.map +1 -1
  22. package/lib/module/index.js +19 -20
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/utils/index.js +1 -1
  25. package/lib/module/utils/index.js.map +1 -1
  26. package/lib/typescript/components/Input/index.d.ts +1 -1
  27. package/package.json +1 -1
  28. package/src/components/CheckBox/index.tsx +1 -1
  29. package/src/components/Dropdown/DropdownFlatList.tsx +5 -3
  30. package/src/components/Dropdown/DropdownSectionList.tsx +6 -3
  31. package/src/components/Input/index.tsx +0 -2
  32. package/src/index.tsx +31 -30
  33. package/src/utils/index.ts +1 -1
package/src/index.tsx CHANGED
@@ -68,11 +68,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
68
68
  const [listIndex, setListIndex] = useState<{
69
69
  sectionIndex?: number;
70
70
  itemIndex: number;
71
- }>({ itemIndex: 0 }); // for scrollToIndex in Sectionlist and Flatlist
72
-
73
- if (!options || options.length === 0) {
74
- throw new Error('Options array cannot be empty or undefined');
75
- }
71
+ }>({ itemIndex: 0, sectionIndex: 0 }); // for scrollToIndex in Sectionlist and Flatlist
76
72
 
77
73
  useEffect(() => {
78
74
  setNewOptions(options);
@@ -92,7 +88,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
92
88
  *==========================================*/
93
89
 
94
90
  // check the structure of the new options array to determine if it is a section list or a
95
- const isSectionList = newOptions.some(
91
+ const isSectionList = newOptions?.some(
96
92
  (item) => item.title && item.data && Array.isArray(item.data)
97
93
  );
98
94
 
@@ -102,17 +98,17 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
102
98
  const modifiedSectionData = extractPropertyFromArray(
103
99
  newOptions,
104
100
  'data'
105
- ).flat();
101
+ )?.flat();
106
102
 
107
103
  /**
108
- *`modifiedOptions` should only be used for computations newOptions remains the default array.
109
- * At this point modifiedOptions now has the same structure for both `FlatList` and `SectionList`
104
+ * `options` is the original array, it never changes. (Do not use except you really need the original array) .
105
+ * `newOptions` is a copy of options but can be mutated by `setNewOptions`, as a result, the value many change.
106
+ * `modifiedOptions` should only be used for computations. It has the same structure for both `FlatList` and `SectionList`
110
107
  */
111
108
  const modifiedOptions = isSectionList ? modifiedSectionData : newOptions;
112
109
 
113
110
  const optLabel = optionLabel || DEFAULT_OPTION_LABEL;
114
111
  const optValue = optionValue || DEFAULT_OPTION_VALUE;
115
- const optionsCopy = JSON.parse(JSON.stringify(options)); // copy of the original options array
116
112
 
117
113
  /*===========================================
118
114
  * Selection handlers
@@ -143,7 +139,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
143
139
  };
144
140
 
145
141
  const removeDisabledItems = (items: TFlatList) => {
146
- return items.filter((item: TFlatListItem) => !item.disabled);
142
+ return items?.filter((item: TFlatListItem) => !item.disabled);
147
143
  };
148
144
 
149
145
  const handleSelectAll = () => {
@@ -153,8 +149,8 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
153
149
  // don't select disabled items
154
150
  const filteredOptions = removeDisabledItems(
155
151
  isSectionList
156
- ? extractPropertyFromArray(optionsCopy, 'data').flat()
157
- : optionsCopy
152
+ ? extractPropertyFromArray(options, 'data').flat()
153
+ : options
158
154
  );
159
155
 
160
156
  if (!prevVal) {
@@ -184,7 +180,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
184
180
  (selectedValues: any[]) => {
185
181
  //if the list contains disabled values, those values will not be selected
186
182
  if (
187
- removeDisabledItems(modifiedOptions).length === selectedValues.length
183
+ removeDisabledItems(modifiedOptions)?.length === selectedValues?.length
188
184
  ) {
189
185
  setSelectAll(true);
190
186
  } else {
@@ -234,10 +230,10 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
234
230
 
235
231
  const regexFilter = new RegExp(searchText, 'i');
236
232
 
237
- // Because the options array will be mutated after Search, we have to search with a copy of the original array
233
+ // Because the options array will be mutated while searching, we have to search with the original array
238
234
  const searchResults = isSectionList
239
- ? searchSectionList(optionsCopy as TSectionList, regexFilter)
240
- : searchFlatList(optionsCopy as TFlatList, regexFilter);
235
+ ? searchSectionList(options as TSectionList, regexFilter)
236
+ : searchFlatList(options as TFlatList, regexFilter);
241
237
 
242
238
  setNewOptions(searchResults);
243
239
  };
@@ -300,18 +296,22 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
300
296
  *==========================================*/
301
297
  const setIndexOfSelectedItem = (selectedLabel: string) => {
302
298
  isSectionList
303
- ? optionsCopy.map((item: TSectionListItem, sectionIndex: number) => {
304
- item.data?.find((dataItem: TFlatListItem, itemIndex: number) => {
305
- if (dataItem[optLabel] === selectedLabel) {
306
- setListIndex({ sectionIndex, itemIndex });
299
+ ? (options as TSectionListItem[] | undefined)?.map(
300
+ (item: TSectionListItem, sectionIndex: number) => {
301
+ item?.data?.find((dataItem: TFlatListItem, itemIndex: number) => {
302
+ if (dataItem[optLabel] === selectedLabel) {
303
+ setListIndex({ sectionIndex, itemIndex });
304
+ }
305
+ });
306
+ }
307
+ )
308
+ : (options as TFlatListItem[] | undefined)?.find(
309
+ (item: TFlatListItem, itemIndex: number) => {
310
+ if (item[optLabel] === selectedLabel) {
311
+ setListIndex({ itemIndex });
307
312
  }
308
- });
309
- })
310
- : optionsCopy?.find((item: TFlatListItem, itemIndex: number) => {
311
- if (item[optLabel] === selectedLabel) {
312
- setListIndex({ itemIndex });
313
313
  }
314
- });
314
+ );
315
315
  };
316
316
 
317
317
  return (
@@ -350,7 +350,6 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
350
350
  modalProps={modalProps}
351
351
  >
352
352
  <ListTypeComponent
353
- removeClippedSubviews={false}
354
353
  ListHeaderComponent={
355
354
  <>
356
355
  {isSearchable && (
@@ -362,12 +361,14 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
362
361
  textInputContainerStyle={
363
362
  searchControls?.textInputContainerStyle
364
363
  }
365
- openModal={() => setOpen(true)} // There seems to a known issue on expo web that closes the modal when the input is focused
364
+ placeholder={
365
+ searchControls?.textInputProps?.placeholder || 'Search'
366
+ }
366
367
  {...searchControls?.textInputProps}
367
368
  />
368
369
  )}
369
370
  {listHeaderComponent}
370
- {isMultiple && modifiedOptions.length > 1 && (
371
+ {isMultiple && modifiedOptions?.length > 1 && (
371
372
  <View style={styles.optionsContainerStyle}>
372
373
  <TouchableOpacity onPress={() => {}}>
373
374
  <CheckBox
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  export const extractPropertyFromArray = (arr: any, property: string) => {
6
- let extractedValue = arr.map((item: any) => item[property]);
6
+ let extractedValue = arr?.map((item: any) => item[property]);
7
7
 
8
8
  return extractedValue;
9
9
  };