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