@widergy/mobile-ui 1.8.2 → 1.8.3

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.8.3](https://github.com/widergy/mobile-ui/compare/v1.8.2...v1.8.3) (2024-05-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * allow persisting selected option in utautocomplete ([#286](https://github.com/widergy/mobile-ui/issues/286)) ([4e0ac6c](https://github.com/widergy/mobile-ui/commit/4e0ac6cb654190a133893ff27820b953dc1c3f30))
7
+
1
8
  ## [1.8.2](https://github.com/widergy/mobile-ui/compare/v1.8.1...v1.8.2) (2024-05-10)
2
9
 
3
10
 
@@ -1,5 +1,5 @@
1
1
  import { arrayOf, bool, element, func, oneOf, shape, string } from 'prop-types';
2
- import React, { useMemo } from 'react';
2
+ import React, { useEffect, useState } from 'react';
3
3
  import { View } from 'react-native';
4
4
 
5
5
  import { WINDOW_HEIGHT } from '../../utils/scaleUtils';
@@ -18,14 +18,19 @@ const UTAutocomplete = ({
18
18
  variant,
19
19
  autoCompletePlaceholder,
20
20
  MenuOptionComponent,
21
- filterOptions
21
+ filterOptions,
22
+ persistSelectedOption = false
22
23
  }) => {
23
- const selectedOption = useMemo(
24
- () => options?.find(option => option.value === input.value),
25
- [options, input.value]
26
- );
24
+ const [selectedOption, setSelectedOption] = useState();
25
+
26
+ useEffect(() => {
27
+ const foundOption = options?.find(option => option.value === input.value);
28
+ if (foundOption || !persistSelectedOption) setSelectedOption(foundOption);
29
+ if (!foundOption && !persistSelectedOption) input.onChange('');
30
+ }, [input, options, persistSelectedOption]);
27
31
 
28
32
  const handleOnPress = item => {
33
+ setSelectedOption(item);
29
34
  input.onChange(item.value);
30
35
  };
31
36
 
@@ -48,7 +53,7 @@ const UTAutocomplete = ({
48
53
  >
49
54
  <UTTextInput
50
55
  variant={variant}
51
- value={selectedOption?.label}
56
+ value={selectedOption?.label || ''}
52
57
  error={error}
53
58
  label={label}
54
59
  labelBackgroundColor={labelBackgroundColor}
@@ -82,7 +87,8 @@ UTAutocomplete.propTypes = {
82
87
  variant: string,
83
88
  autoCompletePlaceholder: string,
84
89
  MenuOptionComponent: element,
85
- filterOptions: bool
90
+ filterOptions: bool,
91
+ persistSelectedOption: bool
86
92
  };
87
93
 
88
94
  export default UTAutocomplete;
@@ -42,7 +42,7 @@ const UTWorkflowContainer = ({
42
42
  return (
43
43
  <SafeAreaView style={themedStyles.container}>
44
44
  {topbar && <UTTopbar {...{ currentStage, currentStep, stages, stepsCount, theme, topbar }} />}
45
- <ScrollView contentContainerStyle={themedStyles.content}>
45
+ <ScrollView contentContainerStyle={themedStyles.content} keyboardShouldPersistTaps="handled">
46
46
  {title && (
47
47
  <UTHeader
48
48
  {...{
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@widergy/mobile-ui",
3
3
  "description": "Widergy Mobile Components",
4
4
  "author": "widergy",
5
- "version": "1.8.2",
5
+ "version": "1.8.3",
6
6
  "repository": "https://github.com/widergy/mobile-ui.git",
7
7
  "main": "lib/index.js",
8
8
  "files": [