All files / src/components modal-backdrop.tsx

14.28% Statements 1/7
100% Branches 0/0
0% Functions 0/3
20% Lines 1/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                16x                                                      
import { useEffect, HTMLAttributes } from 'react';
import cn from 'classnames';
 
type Props = {
  handleExitModal: () => void;
  onWindowOpen: () => void;
};
 
const ModalBackdrop = ({
  className,
  handleExitModal,
  onWindowOpen,
  ...props
}: Props & HTMLAttributes<HTMLDivElement>) => {
  const bodyTag = document.body;
  bodyTag.classList.add('modal__body');
 
  // onWindowOpen not used but leads to console warning as added as
  // attribute. Long term should probably rename prop
 
  // clean-up, when component unmounts.
  useEffect(() => () => bodyTag.classList.remove('modal__body'));
 
  return (
    <div
      className={cn('modal__backdrop', className)}
      onClick={handleExitModal}
      role="dialog"
      aria-hidden
      {...props}
    />
  );
};
 
export default ModalBackdrop;