feat: Automatically closes the DropdownContainer when scrolling outside of the component (#22287)

This commit is contained in:
Michael S. Molina 2022-12-01 10:53:52 -05:00 committed by GitHub
parent 309c064cc8
commit 8cf572858c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -272,6 +272,16 @@ const DropdownContainer = forwardRef(
[ref],
);
// Closes the popover when scrolling on the document
useEffect(() => {
document.onscroll = popoverVisible
? () => setPopoverVisible(false)
: null;
return () => {
document.onscroll = null;
};
}, [popoverVisible]);
return (
<div
ref={ref}