The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Slide the side panel with transform instead of animating its width (#25844)
Louis Delboscf5335676972c
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelForDesktop.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelForDesktop.tsxindex 8a0991ce06f..d0f5116558d 100644--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelForDesktop.tsx+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelForDesktop.tsx@@ -21,20 +21,19 @@ import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomStatimport { styled } from '@linaria/react';import { useReducedMotion } from 'framer-motion';import { useStore } from 'jotai';-import { type AnimationEvent, useCallback, useState } from 'react';+import {+ type AnimationEvent,+ type TransitionEvent,+ useCallback,+ useState,+} from 'react';import { themeCssVariables } from 'twenty-ui/theme-constants';-const StyledSidePanelWrapper = styled.div<{- isOpen: boolean;- isResizing: boolean;-}>`+const StyledSidePanelWrapper = styled.div<{ isOpen: boolean }>`+ background: ${themeCssVariables.background.primary};flex-shrink: 0;min-width: 0;- overflow: hidden;- transition: ${({ isResizing }) =>- isResizing- ? 'none'- : `width calc(${themeCssVariables.animation.duration.normal} * 1s)`};+ position: relative;width: ${({ isOpen }) => (isOpen ? `var(${SIDE_PANEL_WIDTH_VAR})` : '0px')};@keyframes sidePanelShrinkFromFullWidth {@@ -49,7 +48,10 @@ const StyledSidePanelWrapper = styled.div<{}`;-const StyledSidePanel = styled.aside<{ isShrinkingFromFullWidth: boolean }>`+const StyledSidePanel = styled.aside<{+ isOpen: boolean;+ isShrinkingFromFullWidth: boolean;+}>`background: ${themeCssVariables.background.primary};border-left: 1px solid ${themeCssVariables.border.color.medium};box-sizing: border-box;@@ -57,7 +59,12 @@ const StyledSidePanel = styled.aside<{ isShrinkingFromFullWidth: boolean }>`flex-direction: column;height: 100%;overflow: hidden;- position: relative;+ position: absolute;+ right: 0;+ top: 0;+ transform: ${({ isOpen }) => (isOpen ? 'none' : 'translateX(100%)')};+ transition: transform+ calc(${themeCssVariables.animation.duration.normal} * 1s);width: ${({ isShrinkingFromFullWidth }) =>isShrinkingFromFullWidth ? '100%' : `var(${SIDE_PANEL_WIDTH_VAR})`};`;@@ -84,7 +91,6 @@ export const SidePanelForDesktop = () => {const [modalContainer, setModalContainer] = useState<HTMLDivElement | null>(null,);- const [isResizing, setIsResizing] = useState(false);const [shouldRenderContent, setShouldRenderContent] =useState(isSidePanelOpened);const [isShrinkingFromFullWidth, setIsShrinkingFromFullWidth] =@@ -108,7 +114,7 @@ export const SidePanelForDesktop = () => {setShouldRenderContent(true);}- const handleTransitionEnd = () => {+ const handleCloseAnimationComplete = () => {if (isSidePanelOpened) {return;}@@ -120,13 +126,24 @@ export const SidePanelForDesktop = () => {}};+ const handleTransitionEnd = (event: TransitionEvent<HTMLElement>) => {+ if (+ event.target !== event.currentTarget ||+ event.propertyName !== 'transform'+ ) {+ return;+ }++ handleCloseAnimationComplete();+ };+const handleAnimationEnd = (event: AnimationEvent<HTMLDivElement>) => {if (event.target !== event.currentTarget) {return;}setIsShrinkingFromFullWidth(false);- handleTransitionEnd();+ handleCloseAnimationComplete();};const handleModalContainerRef = useCallback(@@ -139,20 +156,17 @@ export const SidePanelForDesktop = () => {const handleWidthChange = useCallback((width: number) => {setSidePanelWidth(width);- setIsResizing(false);setTableWidthResizeIsActive(true);},[setSidePanelWidth, setTableWidthResizeIsActive],);const handleResizeStart = useCallback(() => {- setIsResizing(true);setTableWidthResizeIsActive(false);}, [setTableWidthResizeIsActive]);const handleCollapse = useCallback(() => {closeSidePanelMenu();- setIsResizing(false);setTableWidthResizeIsActive(true);}, [closeSidePanelMenu, setTableWidthResizeIsActive]);@@ -175,14 +189,16 @@ export const SidePanelForDesktop = () => {<StyledSidePanelWrapperisOpen={isSidePanelOpened}- isResizing={isResizing}- onTransitionEnd={handleTransitionEnd}onAnimationEnd={handleAnimationEnd}data-shrink-from-full-width={isShrinkingFromFullWidth}data-side-panel=""data-click-outside-id={SIDE_PANEL_CLICK_OUTSIDE_ID}>- <StyledSidePanel isShrinkingFromFullWidth={isShrinkingFromFullWidth}>+ <StyledSidePanel+ onTransitionEnd={handleTransitionEnd}+ isOpen={isSidePanelOpened}+ isShrinkingFromFullWidth={isShrinkingFromFullWidth}+ ><StyledModalContainer ref={handleModalContainerRef} /><DialogContainerContext.Providervalue={{ container: modalContainer }}diff --git a/packages/twenty-front/src/modules/side-panel/components/__tests__/SidePanelForDesktop.test.tsx b/packages/twenty-front/src/modules/side-panel/components/__tests__/SidePanelForDesktop.test.tsxindex d86e6493c6a..809361b1591 100644--- a/packages/twenty-front/src/modules/side-panel/components/__tests__/SidePanelForDesktop.test.tsx+++ b/packages/twenty-front/src/modules/side-panel/components/__tests__/SidePanelForDesktop.test.tsx@@ -1,4 +1,10 @@-import { act, fireEvent, render } from '@testing-library/react';+import {+ act,+ createEvent,+ fireEvent,+ render,+ screen,+} from '@testing-library/react';import { Provider as JotaiProvider } from 'jotai';import { type ReactNode } from 'react';@@ -188,7 +194,12 @@ describe('SidePanelForDesktop', () => {});fireEvent.animationEnd(wrapperElement);- fireEvent.transitionEnd(wrapperElement);+ const transition = createEvent.transitionEnd(+ screen.getByRole('complementary'),+ );++ Object.defineProperty(transition, 'propertyName', { value: 'transform' });+ fireEvent(screen.getByRole('complementary'), transition);expect(sidePanelCloseAnimationCompleteCleanupMock).toHaveBeenCalledTimes(1);});@@ -203,4 +214,39 @@ describe('SidePanelForDesktop', () => {'false',);});+ it('keeps content mounted until the panel itself finishes sliding closed', () => {+ jotaiStore.set(isSidePanelOpenedState.atom, true);+ render(<SidePanelForDesktop />, { wrapper: Wrapper });++ act(() => {+ jotaiStore.set(isSidePanelOpenedState.atom, false);+ jotaiStore.set(isSidePanelClosingState.atom, true);+ });++ const panel = screen.getByRole('complementary');+ const content = screen.getByTestId('side-panel-content');++ for (const [target, propertyName] of [+ [content, 'transform'],+ [panel, 'opacity'],+ ] as const) {+ const transition = createEvent.transitionEnd(target);++ Object.defineProperty(transition, 'propertyName', {+ value: propertyName,+ });+ fireEvent(target, transition);+ }++ expect(content).toBeInTheDocument();+ expect(sidePanelCloseAnimationCompleteCleanupMock).not.toHaveBeenCalled();++ const transition = createEvent.transitionEnd(panel);++ Object.defineProperty(transition, 'propertyName', { value: 'transform' });+ fireEvent(panel, transition);++ expect(content).not.toBeInTheDocument();+ expect(sidePanelCloseAnimationCompleteCleanupMock).toHaveBeenCalledTimes(1);+ });});