diff --git a/packages/components/src/core/Dropdown/index.tsx b/packages/components/src/core/Dropdown/index.tsx index 5f93bd7c1..88b9ff03c 100644 --- a/packages/components/src/core/Dropdown/index.tsx +++ b/packages/components/src/core/Dropdown/index.tsx @@ -109,10 +109,6 @@ const Dropdown = ({ Value >([]); - useEffect(() => { - onChange(value); - }, [onChange, value]); - useEffect(() => { if (isControlled) { setValue(propValue); @@ -203,7 +199,9 @@ const Dropdown = ({ } if (multiple) { - setValue(pendingValue as Value); + setValueAndCallOnChange( + pendingValue as Value + ); } } } @@ -211,7 +209,9 @@ const Dropdown = ({ function handleClick(event: React.MouseEvent) { if (open) { if (multiple) { - setValue(pendingValue as Value); + setValueAndCallOnChange( + pendingValue as Value + ); } setOpen(false); @@ -221,7 +221,9 @@ const Dropdown = ({ } } else { if (multiple) { - setPendingValue(value as MUIValue); + setValueAndCallOnChange( + pendingValue as Value + ); } setAnchorEl(event.currentTarget); @@ -245,7 +247,9 @@ const Dropdown = ({ } if (multiple) { - setValue(pendingValue as Value); + setValueAndCallOnChange( + newValue as Value + ); } if (anchorEl) { @@ -267,7 +271,10 @@ const Dropdown = ({ if (multiple) { if (isTriggerChangeOnOptionClick) { setPendingValue(newValue as Value); - return setValue(newValue as Value); + + return setValueAndCallOnChange( + newValue as Value + ); } return setPendingValue( @@ -275,7 +282,9 @@ const Dropdown = ({ ); } - setValue(newValue as Value); + setValueAndCallOnChange( + newValue as Value + ); setOpen(false); } @@ -304,6 +313,13 @@ const Dropdown = ({ ? ([] as unknown as Value) : null; } + + function setValueAndCallOnChange( + newValue: Value + ) { + setValue(newValue); + onChange(newValue); + } }; export default Dropdown;