close popup when click outside
This commit is contained in:
parent
2f1f4d7ffd
commit
e93a2417b7
|
|
@ -1,9 +1,20 @@
|
|||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { FaEllipsisH } from 'react-icons/fa';
|
||||
|
||||
const PopupMessage = ({ id }: { id: string }) => {
|
||||
const [show, setShow] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const handleClick = (e: any) => {
|
||||
console.log(show && e.target.closest('.popup-btn'));
|
||||
if ((show && !e.target.closest('.popup-btn') || (e.target.closest('.popup') && !e.target.closest('.popup-btn')))) {
|
||||
setShow(false);
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('click', handleClick);
|
||||
}, [id]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="bg-grey-dark">
|
||||
|
|
|
|||
Loading…
Reference in New Issue