@widergy/mobile-ui 1.4.5 → 1.4.6
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.4.6](https://github.com/widergy/mobile-ui/compare/v1.4.5...v1.4.6) (2024-04-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* allow autocomplete custom behaviour ([#273](https://github.com/widergy/mobile-ui/issues/273)) ([775faf0](https://github.com/widergy/mobile-ui/commit/775faf02c9ed0f184a150d735735dd0a40cd8753))
|
|
7
|
+
|
|
1
8
|
## [1.4.5](https://github.com/widergy/mobile-ui/compare/v1.4.4...v1.4.5) (2024-04-22)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arrayOf, bool, func, oneOf, shape, string } from 'prop-types';
|
|
1
|
+
import { arrayOf, bool, element, func, oneOf, shape, string } from 'prop-types';
|
|
2
2
|
import React, { useMemo } from 'react';
|
|
3
3
|
import { View } from 'react-native';
|
|
4
4
|
|
|
@@ -8,9 +8,19 @@ import UTTextInput from '../UTTextInput';
|
|
|
8
8
|
|
|
9
9
|
import styles from './styles';
|
|
10
10
|
|
|
11
|
-
const UTAutocomplete = ({
|
|
11
|
+
const UTAutocomplete = ({
|
|
12
|
+
input,
|
|
13
|
+
options,
|
|
14
|
+
disabled,
|
|
15
|
+
label,
|
|
16
|
+
error,
|
|
17
|
+
variant,
|
|
18
|
+
autoCompletePlaceholder,
|
|
19
|
+
MenuOptionComponent,
|
|
20
|
+
filterOptions
|
|
21
|
+
}) => {
|
|
12
22
|
const selectedOption = useMemo(
|
|
13
|
-
() => options
|
|
23
|
+
() => options?.find(option => option.value === input.value),
|
|
14
24
|
[options, input.value]
|
|
15
25
|
);
|
|
16
26
|
|
|
@@ -29,8 +39,11 @@ const UTAutocomplete = ({ input, options, disabled, label, error, variant, autoC
|
|
|
29
39
|
onOpen={input.onFocus}
|
|
30
40
|
onClose={input.onBlur}
|
|
31
41
|
disabled={disabled}
|
|
42
|
+
onQueryChange={input.onQueryChange}
|
|
32
43
|
autoCompletePlaceholder={autoCompletePlaceholder}
|
|
33
44
|
maxHeight={WINDOW_HEIGHT * 0.25}
|
|
45
|
+
MenuOptionComponent={MenuOptionComponent}
|
|
46
|
+
filterOptions={filterOptions}
|
|
34
47
|
>
|
|
35
48
|
<UTTextInput
|
|
36
49
|
variant={variant}
|
|
@@ -64,7 +77,9 @@ UTAutocomplete.propTypes = {
|
|
|
64
77
|
label: string,
|
|
65
78
|
error: oneOf([bool, string]),
|
|
66
79
|
variant: string,
|
|
67
|
-
autoCompletePlaceholder: string
|
|
80
|
+
autoCompletePlaceholder: string,
|
|
81
|
+
MenuOptionComponent: element,
|
|
82
|
+
filterOptions: bool
|
|
68
83
|
};
|
|
69
84
|
|
|
70
85
|
export default UTAutocomplete;
|
|
@@ -27,6 +27,8 @@ const UTMenu = ({
|
|
|
27
27
|
maxHeight,
|
|
28
28
|
isMultiple,
|
|
29
29
|
autoCompletePlaceholder,
|
|
30
|
+
onQueryChange,
|
|
31
|
+
filterOptions = true,
|
|
30
32
|
withAutocomplete
|
|
31
33
|
}) => {
|
|
32
34
|
const [isOpen, setIsOpen] = useState(false);
|
|
@@ -37,10 +39,11 @@ const UTMenu = ({
|
|
|
37
39
|
const [menuDimentions, setMenuDimentions] = useState({ width: 0, height: 0 });
|
|
38
40
|
const [query, setQuery] = useState('');
|
|
39
41
|
const searchTextInputRef = useRef();
|
|
40
|
-
const filteredOptions = useMemo(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const filteredOptions = useMemo(() => {
|
|
43
|
+
return filterOptions
|
|
44
|
+
? options.filter(option => !query || option.label.toUpperCase().includes(query.toUpperCase()))
|
|
45
|
+
: options;
|
|
46
|
+
}, [query, options, filterOptions]);
|
|
44
47
|
|
|
45
48
|
const { height: windowHeight, width: windowWidth } = Dimensions.get('window');
|
|
46
49
|
|
|
@@ -97,6 +100,11 @@ const UTMenu = ({
|
|
|
97
100
|
|
|
98
101
|
const focusSearchInput = () => withAutocomplete && searchTextInputRef.current?.focus();
|
|
99
102
|
|
|
103
|
+
const handleQueryChange = value => {
|
|
104
|
+
setQuery(value);
|
|
105
|
+
onQueryChange(value);
|
|
106
|
+
};
|
|
107
|
+
|
|
100
108
|
return (
|
|
101
109
|
<>
|
|
102
110
|
<TouchableOpacity
|
|
@@ -129,7 +137,7 @@ const UTMenu = ({
|
|
|
129
137
|
<UTTextInput
|
|
130
138
|
InputRef={searchTextInputRef}
|
|
131
139
|
value={query}
|
|
132
|
-
onChange={
|
|
140
|
+
onChange={handleQueryChange}
|
|
133
141
|
placeholder={autoCompletePlaceholder}
|
|
134
142
|
onSubmitEditing={
|
|
135
143
|
query && filteredOptions[0]
|
package/package.json
CHANGED