-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PIMS-89 Investigate Removing react-click-away-listener #1907
PIMS-89 Investigate Removing react-click-away-listener #1907
Conversation
The custom clickaway listener that didn't end up getting included: import React, { MutableRefObject, useMemo, useRef } from 'react';
/**
* Hook that alerts clicks outside of the passed ref
*/
const useOutsideAlerter = (ref: MutableRefObject<unknown>, onClickAway: () => void) => {
useMemo(() => {
/**
* Alert if clicked on outside of element
*/
const handleClickOutside: EventListener = (event) => {
if (
ref.current &&
ref.current !== null &&
!(ref.current as HTMLDivElement).contains(event.target as Node)
) {
onClickAway();
}
};
// Bind the event listener
document.addEventListener('mouseup', handleClickOutside);
return () => {
// Unbind the event listener on clean up
document.removeEventListener('mouseup', handleClickOutside);
};
}, [ref]);
};
interface IClickAwayListenerProps {
children: React.ReactElement;
onClickAway: () => void;
}
/**
* Component that alerts if you click outside of it
*/
const ClickAwayListener = (props: IClickAwayListenerProps) => {
const { children, onClickAway } = props;
const wrapperRef: MutableRefObject<HTMLDivElement | null> = useRef(null);
useOutsideAlerter(wrapperRef, onClickAway);
return <div ref={wrapperRef}>{children}</div>;
};
export default ClickAwayListener; |
Code Climate has analyzed commit 020d569 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 55.4%. View more on Code Climate. |
🚀 Deployment Information The APP Image has been built with the tag: |
🎯 Summary
PIMS-89:
Looked at removing/replacing the react-click-away-listener with something custom.
It was working in all situations except one, which was just a strange implementation, I think.
Tried to write a custom one, which worked everywhere except the table filters. Ended up just keeping the existing package, as there's no strong reason to remove it at this point and it is working.
I'll include the custom code below for future use.
Also had to add console.error suppression for a recently updated test.
🔰 Checklist