From ea0e8e51e0ff2b8a54fd3afcc4365d40e0c48e3e Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Thu, 19 Sep 2024 10:07:13 +0930 Subject: [PATCH] fix: Modal animation improved - reduce complexity - works 100% of the time now - fades in / out rather than up / down --- frontend/src/components/ui/Modal.jsx | 39 +++++++--------------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/frontend/src/components/ui/Modal.jsx b/frontend/src/components/ui/Modal.jsx index ca249cc..1c1accf 100644 --- a/frontend/src/components/ui/Modal.jsx +++ b/frontend/src/components/ui/Modal.jsx @@ -1,4 +1,4 @@ -import {useEffect, useRef, useState} from 'react'; +import React, {useEffect, useRef} from 'react'; import PropTypes from 'prop-types'; function Modal({ @@ -13,25 +13,6 @@ function Modal({ height = 'auto' }) { const modalRef = useRef(); - const [isAnimating, setIsAnimating] = useState(false); - const [shouldRender, setShouldRender] = useState(false); - const [isClosing, setIsClosing] = useState(false); - - useEffect(() => { - if (isOpen) { - setIsClosing(false); - setShouldRender(true); - setTimeout(() => setIsAnimating(true), 10); - } else { - setIsClosing(true); - setIsAnimating(false); - const timer = setTimeout(() => { - setShouldRender(false); - setIsClosing(false); - }, 300); - return () => clearTimeout(timer); - } - }, [isOpen]); useEffect(() => { if (isOpen && !disableCloseOnEscape) { @@ -47,8 +28,6 @@ function Modal({ } }, [isOpen, onClose, disableCloseOnEscape]); - if (!shouldRender && !isClosing) return null; - const handleClickOutside = e => { if ( modalRef.current && @@ -95,13 +74,15 @@ function Modal({ return (
+ onClick={handleClickOutside}>