🐛 fix(inputListComponent): fix onChange event not being triggered when input value changes

 feat(inputListComponent): add PopUpContext to be able to close pop-ups when input value changes
This commit is contained in:
Cristhian Zanforlin Lousa 2023-06-23 20:15:44 -03:00
commit 6cc4106c23

View file

@ -5,6 +5,7 @@ import { TabsContext } from "../../contexts/tabsContext";
import _ from "lodash";
import { INPUT_STYLE } from "../../constants";
import { X, Plus } from "lucide-react";
import { PopUpContext } from "../../contexts/popUpContext";
export default function InputListComponent({
value,
@ -13,6 +14,8 @@ export default function InputListComponent({
editNode = false,
}: InputListComponentType) {
const [inputList, setInputList] = useState(value ?? [""]);
const { closePopUp } = useContext(PopUpContext);
useEffect(() => {
if (disabled) {
setInputList([""]);
@ -22,8 +25,10 @@ export default function InputListComponent({
useEffect(() => {
setInputList(value);
}, [value]);
}, [closePopUp]);
return (
<div
className={
@ -49,9 +54,9 @@ export default function InputListComponent({
setInputList((old) => {
let newInputList = _.cloneDeep(old);
newInputList[idx] = e.target.value;
onChange(newInputList);
return newInputList;
});
onChange(inputList);
}}
/>
{idx === inputList.length - 1 ? (