Skip to content

Commit

Permalink
use recuded motion for modal
Browse files Browse the repository at this point in the history
  • Loading branch information
LeunensMichiel committed Dec 22, 2021
1 parent bc96b99 commit ba28dc7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions components/ui/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
enableBodyScroll,
} from 'body-scroll-lock';
import cn from 'classnames';
import { AnimatePresence, motion } from 'framer-motion';
import { AnimatePresence, motion, useReducedMotion } from 'framer-motion';
import { FC, MutableRefObject, useCallback, useEffect, useRef } from 'react';
import FocusLock from 'react-focus-lock';

Expand Down Expand Up @@ -44,6 +44,8 @@ const Modal: FC<ModalProps> = ({
title,
}) => {
const ref = useRef() as MutableRefObject<HTMLDivElement>;
const shouldReduceMotion = useReducedMotion();
const closedY = shouldReduceMotion ? 0 : 200;
const duration = 0.3;
useClickOutside(ref, () => onClose());

Expand Down Expand Up @@ -90,9 +92,12 @@ const Modal: FC<ModalProps> = ({
exit="closed"
variants={{
open: { opacity: 1, y: 0 },
closed: { opacity: 0, y: 200 },
closed: { opacity: 0, y: closedY },
}}
transition={{
duration,
type: 'spring',
}}
transition={{ duration }}
aria-modal
aria-labelledby={title}
tabIndex={-1}
Expand Down

0 comments on commit ba28dc7

Please sign in to comment.