diff --git a/src/components/Modal/index.tsx b/src/components/Modal/index.tsx index b74909b..e2129d5 100644 --- a/src/components/Modal/index.tsx +++ b/src/components/Modal/index.tsx @@ -3,11 +3,22 @@ import {createPortal} from 'react-dom'; import {TModalProps} from './types'; -const Modal = ({refItem, className, children}: TModalProps) => { +const Modal = ({refItem, className, children, onClose}: TModalProps) => { + const handleClose = (e: React.MouseEvent) => { + e.stopPropagation(); + + if (refItem?.current?.contains(e.target as Node)) { + return; + } + + onClose(); + }; + return ( <> {createPortal(
; - onClose: (refId: string) => void; + onClose: () => void; className?: string; }>; diff --git a/src/components/inputs/Dropdown/index.tsx b/src/components/inputs/Dropdown/index.tsx index 229dca5..209c3b5 100644 --- a/src/components/inputs/Dropdown/index.tsx +++ b/src/components/inputs/Dropdown/index.tsx @@ -19,7 +19,7 @@ const Dropdown = ({ }: TDropdownProps) => { const [currentValue, setCurrentValue] = useState(selectedOption); - const {ref, isOpen, handleClose, handleToggle} = useOpeningItem(); + const {isOpen, handleClose, handleToggle} = useOpeningItem(); const activeOptionRef = useRef(null); const handleChange = useCallback( @@ -29,9 +29,7 @@ const Dropdown = ({ setCurrentValue(option); - setTimeout(() => { - handleClose(); - }, 0); + handleClose(); }, [field, handleClose, onChange], ); @@ -54,10 +52,10 @@ const Dropdown = ({ }, [isOpen, activeOptionRef]); return ( -
+