Skip to content

The open alternative to Salesforce, designed for AI.

Animate navigation mode label transitions (#25345)

Thomas des Francs11f218ae4e69
diff --git a/packages/twenty-front/src/modules/navigation/components/AppNavigationDrawer.tsx b/packages/twenty-front/src/modules/navigation/components/AppNavigationDrawer.tsx
index 6df9cea0a88..876195ac20b 100644
--- a/packages/twenty-front/src/modules/navigation/components/AppNavigationDrawer.tsx
+++ b/packages/twenty-front/src/modules/navigation/components/AppNavigationDrawer.tsx
@@ -1,7 +1,10 @@
import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';
-import { MainNavigationDrawer } from '@/navigation/components/MainNavigationDrawer';
-import { SettingsNavigationDrawer } from '@/navigation/components/SettingsNavigationDrawer';
+import { MainNavigationDrawerContent } from '@/navigation/components/MainNavigationDrawerContent';
+import { MainNavigationDrawerModeSwitcher } from '@/navigation/components/MainNavigationDrawerModeSwitcher';
+import { SettingsNavigationDrawerContent } from '@/navigation/components/SettingsNavigationDrawerContent';
+import { NavigationDrawer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawer';
+import { NavigationDrawerFixedContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerFixedContent';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
export type AppNavigationDrawerProps = {
@@ -14,14 +17,22 @@ export const AppNavigationDrawer = ({
const isMobile = useIsMobile();
const isSettingsDrawer = useIsSettingsDrawer();
- if (isSettingsDrawer) {
- return <SettingsNavigationDrawer className={className} />;
- }
-
// The main navigation is the home page on mobile, not a drawer.
- if (isMobile) {
+ if (isMobile && !isSettingsDrawer) {
return null;
}
- return <MainNavigationDrawer className={className} />;
+ return (
+ <NavigationDrawer className={className}>
+ <NavigationDrawerFixedContent>
+ <MainNavigationDrawerModeSwitcher />
+ </NavigationDrawerFixedContent>
+
+ {isSettingsDrawer ? (
+ <SettingsNavigationDrawerContent />
+ ) : (
+ <MainNavigationDrawerContent />
+ )}
+ </NavigationDrawer>
+ );
};
diff --git a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawer.tsx b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerContent.tsx
similarity index 51%
rename from packages/twenty-front/src/modules/navigation/components/MainNavigationDrawer.tsx
rename to packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerContent.tsx
index d3b3f0e42dc..c72ea0ab8a4 100644
--- a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawer.tsx
+++ b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerContent.tsx
@@ -1,15 +1,12 @@
-import { MainNavigationDrawerModeSwitcher } from '@/navigation/components/MainNavigationDrawerModeSwitcher';
import { MainNavigationDrawerNavigationContent } from '@/navigation/components/MainNavigationDrawerNavigationContent';
import { NavigationDrawerTabbedContent } from '@/navigation/components/NavigationDrawerTabbedContent';
import { useActiveNavigationDrawerMode } from '@/navigation/hooks/useActiveNavigationDrawerMode';
import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
-import { NavigationDrawer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawer';
-import { NavigationDrawerFixedContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerFixedContent';
import { NavigationDrawerScrollableContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerScrollableContent';
import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';
import { PermissionFlagType } from '~/generated-metadata/graphql';
-export const MainNavigationDrawer = ({ className }: { className?: string }) => {
+export const MainNavigationDrawerContent = () => {
const activeNavigationDrawerMode = useActiveNavigationDrawerMode();
const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
@@ -18,18 +15,12 @@ export const MainNavigationDrawer = ({ className }: { className?: string }) => {
activeNavigationDrawerMode === NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY;
return (
- <NavigationDrawer className={className}>
- <NavigationDrawerFixedContent>
- <MainNavigationDrawerModeSwitcher />
- </NavigationDrawerFixedContent>
-
- <NavigationDrawerScrollableContent>
- <NavigationDrawerTabbedContent
- showAiChatContent={showAiChatContent}
- shouldMountAiChatContent={hasAiPermission}
- navigationContent={<MainNavigationDrawerNavigationContent />}
- />
- </NavigationDrawerScrollableContent>
- </NavigationDrawer>
+ <NavigationDrawerScrollableContent>
+ <NavigationDrawerTabbedContent
+ showAiChatContent={showAiChatContent}
+ shouldMountAiChatContent={hasAiPermission}
+ navigationContent={<MainNavigationDrawerNavigationContent />}
+ />
+ </NavigationDrawerScrollableContent>
);
};
diff --git a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx
index 5d04efefbf0..62048f3bf8f 100644
--- a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx
+++ b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx
@@ -1,5 +1,6 @@
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
+import { motion, useReducedMotion } from 'framer-motion';
import { useContext } from 'react';
import {
type IconComponent,
@@ -76,21 +77,14 @@ const StyledModeIcon = styled.span`
width: ${themeCssVariables.spacing[4]};
`;
-// The label of an inactive mode stays in the tree so the button keeps an
-// accessible name, and the collapsed track wipes it open on activation.
-const StyledModeLabel = styled.span<{ isActive: boolean }>`
- display: grid;
- grid-template-columns: ${({ isActive }) => (isActive ? '1fr' : '0fr')};
- transition: grid-template-columns
- calc(${themeCssVariables.animation.duration.normal} * 1s) ease;
-`;
-
-const StyledModeLabelText = styled.span`
- min-width: 0;
+const StyledModeLabelBase = styled.span`
+ display: block;
overflow: hidden;
white-space: nowrap;
`;
+const StyledModeLabel = motion.create(StyledModeLabelBase);
+
type NavigationDrawerMode = {
Icon: IconComponent;
label: string;
@@ -104,6 +98,7 @@ export const MainNavigationDrawerModeSwitcher = () => {
const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
const activeNavigationDrawerMode = useActiveNavigationDrawerMode();
const { switchNavigationDrawerMode } = useSwitchNavigationDrawerMode();
+ const shouldReduceMotion = useReducedMotion();
const isWorkspaceSuspended = useIsWorkspaceActivationStatusEqualsTo(
WorkspaceActivationStatus.SUSPENDED,
@@ -149,14 +144,24 @@ export const MainNavigationDrawerModeSwitcher = () => {
key={mode}
type="button"
isActive={isActive}
+ aria-label={label}
aria-current={isActive}
onClick={() => switchNavigationDrawerMode(mode)}
>
<StyledModeIcon>
<Icon size={theme.icon.size.md} />
</StyledModeIcon>
- <StyledModeLabel isActive={isActive}>
- <StyledModeLabelText>{label}</StyledModeLabelText>
+ <StyledModeLabel
+ initial={false}
+ animate={{ width: isActive ? 'auto' : 0 }}
+ transition={{
+ duration: shouldReduceMotion
+ ? 0
+ : theme.animation.duration.normal,
+ ease: 'easeInOut',
+ }}
+ >
+ {label}
</StyledModeLabel>
</StyledMode>
);
diff --git a/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx b/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawerContent.tsx
similarity index 76%
rename from packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx
rename to packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawerContent.tsx
index 5e91423a914..7a46a001538 100644
--- a/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx
+++ b/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawerContent.tsx
@@ -1,7 +1,4 @@
-import { MainNavigationDrawerModeSwitcher } from '@/navigation/components/MainNavigationDrawerModeSwitcher';
import { SettingsNavigationDrawerItems } from '@/settings/components/SettingsNavigationDrawerItems';
-import { NavigationDrawer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawer';
-import { NavigationDrawerFixedContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerFixedContent';
import { NavigationDrawerScrollableContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerScrollableContent';
import { NavigationDrawerSection } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSection';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
@@ -26,11 +23,7 @@ const advancedSettingsToggleClassName = css`
padding-right: 0;
`;
-export const SettingsNavigationDrawer = ({
- className,
-}: {
- className?: string;
-}) => {
+export const SettingsNavigationDrawerContent = () => {
const { t } = useLingui();
const isMobile = useIsMobile();
const [isAdvancedModeEnabled, setIsAdvancedModeEnabled] = useAtomState(
@@ -38,11 +31,7 @@ export const SettingsNavigationDrawer = ({
);
return (
- <NavigationDrawer className={className}>
- <NavigationDrawerFixedContent>
- <MainNavigationDrawerModeSwitcher />
- </NavigationDrawerFixedContent>
-
+ <>
<NavigationDrawerScrollableContent>
<SettingsNavigationDrawerItems />
</NavigationDrawerScrollableContent>
@@ -57,6 +46,6 @@ export const SettingsNavigationDrawer = ({
/>
</NavigationDrawerSection>
</StyledAdvancedToggleFixedContent>
- </NavigationDrawer>
+ </>
);
};
diff --git a/packages/twenty-front/src/modules/navigation/components/__tests__/AppNavigationDrawer.test.tsx b/packages/twenty-front/src/modules/navigation/components/__tests__/AppNavigationDrawer.test.tsx
new file mode 100644
index 00000000000..2ca682acfc4
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/components/__tests__/AppNavigationDrawer.test.tsx
@@ -0,0 +1,64 @@
+import { AppNavigationDrawer } from '@/navigation/components/AppNavigationDrawer';
+import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';
+import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
+import { render, screen } from '@testing-library/react';
+import { type ReactNode } from 'react';
+
+jest.mock('@/navigation/hooks/useIsSettingsDrawer');
+jest.mock('@/ui/utilities/responsive/hooks/useIsMobile');
+
+jest.mock('@/navigation/components/MainNavigationDrawerContent', () => ({
+ MainNavigationDrawerContent: () => <div>Main content</div>,
+}));
+
+jest.mock('@/navigation/components/MainNavigationDrawerModeSwitcher', () => ({
+ MainNavigationDrawerModeSwitcher: () => (
+ <button type="button">Navigation modes</button>
+ ),
+}));
+
+jest.mock('@/navigation/components/SettingsNavigationDrawerContent', () => ({
+ SettingsNavigationDrawerContent: () => <div>Settings content</div>,
+}));
+
+jest.mock(
+ '@/ui/navigation/navigation-drawer/components/NavigationDrawer',
+ () => ({
+ NavigationDrawer: ({ children }: { children: ReactNode }) => (
+ <aside>{children}</aside>
+ ),
+ }),
+);
+
+jest.mock(
+ '@/ui/navigation/navigation-drawer/components/NavigationDrawerFixedContent',
+ () => ({
+ NavigationDrawerFixedContent: ({ children }: { children: ReactNode }) => (
+ <>{children}</>
+ ),
+ }),
+);
+
+describe('AppNavigationDrawer', () => {
+ beforeEach(() => {
+ jest.mocked(useIsMobile).mockReturnValue(false);
+ jest.mocked(useIsSettingsDrawer).mockReturnValue(false);
+ });
+
+ it('keeps the mode switcher mounted when the drawer content changes', () => {
+ const { rerender } = render(<AppNavigationDrawer />);
+ const modeSwitcher = screen.getByRole('button', {
+ name: 'Navigation modes',
+ });
+
+ expect(screen.getByText('Main content')).toBeInTheDocument();
+
+ jest.mocked(useIsSettingsDrawer).mockReturnValue(true);
+ rerender(<AppNavigationDrawer />);
+
+ expect(screen.getByText('Settings content')).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Navigation modes' })).toBe(
+ modeSwitcher,
+ );
+ });
+});
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerAnimatedCollapseWrapper.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerAnimatedCollapseWrapper.tsx
index 258c96610ce..b3c7ded19df 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerAnimatedCollapseWrapper.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerAnimatedCollapseWrapper.tsx
@@ -23,24 +23,21 @@ export const NavigationDrawerAnimatedCollapseWrapper = ({
const isSettingsPage = useIsSettingsPage();
const isNavigationDrawerExpanded = useIsNavigationDrawerContentExpanded();
- if (isSettingsPage) {
- return children;
- }
+ const shouldShowContent = isSettingsPage || isNavigationDrawerExpanded;
- const animate: AnimationControls | TargetAndTransition =
- isNavigationDrawerExpanded
- ? {
- opacity: 1,
- width: 'auto',
- height: 'auto',
- pointerEvents: 'auto',
- }
- : {
- opacity: 0,
- width: 0,
- height: 0,
- pointerEvents: 'none',
- };
+ const animate: AnimationControls | TargetAndTransition = shouldShowContent
+ ? {
+ opacity: 1,
+ width: 'auto',
+ height: 'auto',
+ pointerEvents: 'auto',
+ }
+ : {
+ opacity: 0,
+ width: 0,
+ height: 0,
+ pointerEvents: 'none',
+ };
return (
<StyledAnimatedContainer
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__tests__/NavigationDrawerAnimatedCollapseWrapper.test.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__tests__/NavigationDrawerAnimatedCollapseWrapper.test.tsx
new file mode 100644
index 00000000000..cd055cd579b
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__tests__/NavigationDrawerAnimatedCollapseWrapper.test.tsx
@@ -0,0 +1,58 @@
+import { useIsNavigationDrawerContentExpanded } from '@/navigation/hooks/useIsNavigationDrawerContentExpanded';
+import { useIsSettingsPage } from '@/navigation/hooks/useIsSettingsPage';
+import { NavigationDrawerAnimatedCollapseWrapper } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerAnimatedCollapseWrapper';
+import { render, screen, waitFor } from '@testing-library/react';
+
+jest.mock('@/navigation/hooks/useIsNavigationDrawerContentExpanded');
+jest.mock('@/navigation/hooks/useIsSettingsPage');
+
+const NavigationModes = () => (
+ <NavigationDrawerAnimatedCollapseWrapper>
+ <button type="button">Navigation modes</button>
+ </NavigationDrawerAnimatedCollapseWrapper>
+);
+
+describe('NavigationDrawerAnimatedCollapseWrapper', () => {
+ beforeEach(() => {
+ jest.mocked(useIsNavigationDrawerContentExpanded).mockReturnValue(false);
+ jest.mocked(useIsSettingsPage).mockReturnValue(true);
+ });
+
+ it('keeps its children mounted while collapsing and expanding around settings', async () => {
+ const { rerender } = render(<NavigationModes />);
+ const navigationModesButton = screen.getByRole('button', {
+ name: 'Navigation modes',
+ });
+ const animatedContainer = navigationModesButton.parentElement;
+
+ jest.mocked(useIsSettingsPage).mockReturnValue(false);
+ rerender(<NavigationModes />);
+
+ await waitFor(() => {
+ expect(animatedContainer).toHaveStyle({
+ height: '0px',
+ pointerEvents: 'none',
+ width: '0px',
+ });
+ });
+
+ expect(screen.getByRole('button', { name: 'Navigation modes' })).toBe(
+ navigationModesButton,
+ );
+
+ jest.mocked(useIsSettingsPage).mockReturnValue(true);
+ rerender(<NavigationModes />);
+
+ await waitFor(() => {
+ expect(animatedContainer).toHaveStyle({
+ height: 'auto',
+ pointerEvents: 'auto',
+ width: 'auto',
+ });
+ });
+
+ expect(screen.getByRole('button', { name: 'Navigation modes' })).toBe(
+ navigationModesButton,
+ );
+ });
+});