fixed bug that prev item is selected on modal open
parent
7b682b422f
commit
784133fb60
|
@ -1,4 +1,4 @@
|
|||
import { useContext, useState } from "react";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { AppContext, AppStyles } from "../../utils";
|
||||
import { Modal, Text, TextInput, TouchableOpacity, View } from "react-native";
|
||||
import { Divider } from "../Divider";
|
||||
|
@ -13,9 +13,11 @@ export default function PickerModal({
|
|||
}) {
|
||||
const appContext = useContext(AppContext);
|
||||
const { t } = useTranslation();
|
||||
const [providedItems, setProvidedItems] = useState(items);
|
||||
const [providedItems, setProvidedItems] = useState([]);
|
||||
const [searchFilterInput, setSearchFilterInput] = useState("");
|
||||
|
||||
useEffect(() => setProvidedItems(items), [items]);
|
||||
|
||||
const closeModal = () => {
|
||||
setIsOpen(false);
|
||||
setProvidedItems(items);
|
||||
|
@ -75,15 +77,13 @@ export default function PickerModal({
|
|||
onChangeText={(text) => {
|
||||
setSearchFilterInput(text);
|
||||
|
||||
setProvidedItems((provItems) => {
|
||||
let newProvItems = [...provItems];
|
||||
|
||||
newProvItems = items.filter((provItem) => {
|
||||
return provItem.label.startsWith(text);
|
||||
});
|
||||
|
||||
return newProvItems;
|
||||
});
|
||||
setProvidedItems(() =>
|
||||
items.filter((provItem) => {
|
||||
return provItem.label
|
||||
.toLowerCase()
|
||||
.startsWith(text.toLowerCase());
|
||||
})
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{searchFilterInput !== "" && (
|
||||
|
|
Loading…
Reference in New Issue