✨(react) add a popover component
A design system needs a popover mecanism. In the select component, this logic is handled by downshift. We introduce a new component, responsible to open an element in a popin and close it when the user click outside of it.
This commit is contained in:
committed by
aleb_the_flash
parent
f967775fb6
commit
1d1cf81cf6
18
packages/react/src/hooks/useHandleClickOutside.ts
Normal file
18
packages/react/src/hooks/useHandleClickOutside.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { RefObject, useEffect } from "react";
|
||||
|
||||
export const useHandleClickOutside = (
|
||||
ref: RefObject<HTMLDivElement>,
|
||||
onClickOutside: any
|
||||
) => {
|
||||
useEffect(() => {
|
||||
const outsideListenerEvent = (event: MouseEvent) => {
|
||||
if (!ref.current || ref.current.contains(event.target as Node)) {
|
||||
return;
|
||||
}
|
||||
onClickOutside();
|
||||
};
|
||||
document.addEventListener("click", outsideListenerEvent, true);
|
||||
return () =>
|
||||
document.removeEventListener("click", outsideListenerEvent, true);
|
||||
}, []);
|
||||
};
|
||||
Reference in New Issue
Block a user