Skip to content

Commit

Permalink
Add backup timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 10, 2024
1 parent 2dc7f84 commit 1d9e094
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/components/src/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import StyleProvider from '../style-provider';
import type { ModalProps } from './types';
import { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';

// Animation duration (ms) extracted to JS in order to be used on a setTimeout.
const FRAME_ANIMATION_DURATION = 260;

// Used to track and dismiss the prior modal when another opens unless nested.
type Dismissers = Set<
RefObject< ModalProps[ 'onRequestClose' ] | undefined >
Expand Down Expand Up @@ -215,6 +218,10 @@ function UnforwardedModal(
frameEl.addEventListener( 'animationend', onAnimationEnd, {
once: true,
} );
const animationTimeout = window.setTimeout( () => {
setIsAnimatingOut( false );
onRequestCloseRef.current?.( event );
}, FRAME_ANIMATION_DURATION );

return () => {
frameEl.removeEventListener( 'animationend', onAnimationEnd );
Expand Down Expand Up @@ -310,7 +317,10 @@ function UnforwardedModal(
sizeClass,
className
) }
style={ style }
style={ {
'--modal-frame-animation-duration': `${ FRAME_ANIMATION_DURATION }ms`,
...style,
} }
ref={ useMergeRefs( [
frameRef,
constrainedTabbingRef,
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/modal/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// Have the content element fill the vertical space yet not overflow.
display: flex;
// Animate the modal frame/contents appearing on the page.
animation: components-modal__appear-animation 0.26s cubic-bezier(0.29, 0, 0, 1);
animation: components-modal__appear-animation var(--modal-frame-animation-duration) cubic-bezier(0.29, 0, 0, 1);
animation-fill-mode: forwards;
@include reduce-motion("animation");

Expand Down

0 comments on commit 1d9e094

Please sign in to comment.