🐛 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:
parent
4e01de9e39
commit
6cc4106c23
1 changed files with 7 additions and 2 deletions
|
|
@ -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 ? (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue