Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions packages/web/src/overlays/overlay/OverlayContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ export const OverlayContent = forwardRef<HTMLDivElement, OverlayProps>(
exit: 'exit',
});

const content = (
<VStack ref={forwardedRef} background="bgOverlay" onClick={onClick} pin="all" {...props} />
);

return animated ? (
<motion.div {...motionProps} data-testid={`${props.testID}-motion`}>
{content}
<motion.div ref={forwardedRef} {...motionProps} data-testid={`${props.testID}-motion`}>
<VStack background="bgOverlay" onClick={onClick} pin="all" {...props} />
</motion.div>
) : (
content
<VStack ref={forwardedRef} background="bgOverlay" onClick={onClick} pin="all" {...props} />
);
},
);
Expand Down
9 changes: 9 additions & 0 deletions packages/web/src/overlays/tray/Tray.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export const Tray = memo(
const trayRef = useRef<HTMLDivElement>(null);
const { observe: observeTraySize, height: trayHeight } = useDimensions<HTMLDivElement>();
const contentRef = useRef<HTMLDivElement>(null);
const overlayRef = useRef<HTMLDivElement>(null);
const hasCalledOnOpenComplete = useRef(false);
const [scope, animate] = useAnimate();
const dragControls = useDragControls();
Expand Down Expand Up @@ -317,6 +318,9 @@ export const Tray = memo(
? { x: pin === 'right' ? '100%' : '-100%' }
: { y: pin === 'bottom' ? '100%' : '-100%' };
}
if (overlayRef.current) {
animate(overlayRef.current, { opacity: 0 }, animationConfig.slideOut.transition);
}
animate(scope.current, finalAnimationValue, animationConfig.slideOut.transition).then(() => {
setIsOpen(false);
onClose?.();
Expand All @@ -326,6 +330,9 @@ export const Tray = memo(

const handleSwipeClose = useCallback(() => {
if (!scope.current) return;
if (overlayRef.current) {
animate(overlayRef.current, { opacity: 0 }, { duration: 0.15, ease: 'easeOut' });
}
animate(scope.current, { y: '100%' }, { duration: 0.15, ease: 'easeOut' }).then(() => {
setIsOpen(false);
onBlur?.();
Expand Down Expand Up @@ -451,6 +458,8 @@ export const Tray = memo(
zIndex={zIndex}
>
<Overlay
ref={overlayRef}
animated
className={cx(trayClassNames.overlay, classNames?.overlay)}
onClick={handleOverlayClick}
style={styles?.overlay}
Expand Down
14 changes: 14 additions & 0 deletions packages/web/src/overlays/tray/__tests__/Tray.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,18 @@ describe('Tray', () => {
expect(root?.querySelector(`.${trayClassNames.handleBarHandle}`)).toBeInTheDocument();
});
});

describe('overlay animation', () => {
it('wraps the overlay in a motion container so the backdrop fades', () => {
const onCloseCompleteSpy = jest.fn();
render(
<DefaultThemeProvider>
<Tray onCloseComplete={onCloseCompleteSpy} title={titleText}>
{loremIpsum}
</Tray>
</DefaultThemeProvider>,
);
expect(screen.getByTestId('tray-overlay-motion')).toBeInTheDocument();
});
});
});
Loading