diff --git a/app/components/navbar/nav-item-with-dropdown.tsx b/app/components/navbar/nav-item-with-dropdown.tsx index 228c53c6..d089ddd8 100644 --- a/app/components/navbar/nav-item-with-dropdown.tsx +++ b/app/components/navbar/nav-item-with-dropdown.tsx @@ -31,7 +31,8 @@ export function NavItemWithDropdown({ const triggerStyles = cx( flex({ gap: '1', align: 'center' }), css({ - px: '4', + // Same spacing as the plain links in `navbar.tsx`. + px: { base: '4', lg: '3', xl: '4' }, py: '2', rounded: 'full', fontSize: 'sm', @@ -41,6 +42,7 @@ export function NavItemWithDropdown({ transitionDuration: 'slow', color: isOpen || isCurrentPath ? 'ocobo.dark' : 'gray.500', _hover: { color: 'ocobo.dark' }, + whiteSpace: 'nowrap', }), ); diff --git a/app/components/navbar/navbar.test.tsx b/app/components/navbar/navbar.test.tsx index ef1e865b..a9b8f40f 100644 --- a/app/components/navbar/navbar.test.tsx +++ b/app/components/navbar/navbar.test.tsx @@ -91,22 +91,29 @@ const withChallenges = (challenges: ChallengeMenuEntry[], failed = false) => ({ }); describe('Navbar challenge entry', () => { - it('is hidden when no challenge is published', () => { + it('is hidden when no challenge is published, and the offer stays', () => { render(, withChallenges([])); expect( screen.queryByRole('button', { name: /vos enjeux/i }), ).not.toBeInTheDocument(); + expect( + screen.getByRole('link', { name: 'Notre Offre' }), + ).toBeInTheDocument(); }); - it('comes first and lists the challenges in the order given', async () => { + it('replaces the offer entry and lists the challenges in order', async () => { const user = userEvent.setup(); render(, withChallenges(frenchChallenges)); const trigger = screen.getByRole('button', { name: /vos enjeux/i }); - const offer = screen.getByRole('link', { name: 'Notre Offre' }); expect( - trigger.compareDocumentPosition(offer) & Node.DOCUMENT_POSITION_FOLLOWING, + screen.queryByRole('link', { name: 'Notre Offre' }), + ).not.toBeInTheDocument(); + const stories = screen.getByRole('link', { name: 'Success Stories' }); + expect( + trigger.compareDocumentPosition(stories) & + Node.DOCUMENT_POSITION_FOLLOWING, ).toBeTruthy(); await user.click(trigger); diff --git a/app/components/navbar/navbar.tsx b/app/components/navbar/navbar.tsx index c5e26d18..574c8b7a 100644 --- a/app/components/navbar/navbar.tsx +++ b/app/components/navbar/navbar.tsx @@ -19,7 +19,8 @@ const getLinkStyles = (isDropdownActive: boolean, isCurrent: boolean) => cx( flex({ gap: '1', align: 'center' }), css({ - px: '4', + // Tighter between 1024px and 1280px, so the bar stays on one line. + px: { base: '4', lg: '3', xl: '4' }, py: '2', rounded: 'full', fontSize: 'sm', @@ -71,7 +72,8 @@ export function Navbar() { className={css({ position: 'relative', w: 'full', - maxW: scrolled ? '5xl' : '7xl', + // 6xl holds every item on one line once the challenges entry shows. + maxW: scrolled ? '6xl' : '7xl', transition: 'all', transitionDuration: '[700ms]', transitionTimingFunction: 'smooth', @@ -136,7 +138,7 @@ export function Navbar() { {/* Desktop Navigation */}
{ + it('puts the challenge entry in the place of the offer entry', () => { + const items = placeChallengeItem([offer, stories, contact], challenges); + + expect(items.map((item) => item.key)).toEqual([ + 'challenges', + 'stories', + 'contact', + ]); + expect(items[0]).toBe(challenges); + }); + + it('keeps the offer entry when no challenge is published', () => { + const items = [offer, stories, contact]; + + expect(placeChallengeItem(items, null)).toEqual([offer, stories, contact]); + }); + + it('keeps the challenge entry, first, when there is no offer entry', () => { + const items = placeChallengeItem([stories, contact], challenges); + + expect(items.map((item) => item.key)).toEqual([ + 'challenges', + 'stories', + 'contact', + ]); + }); + + it('does not mutate the given list', () => { + const items = [offer, stories]; + + placeChallengeItem(items, challenges); + + expect(items).toEqual([offer, stories]); + }); +}); diff --git a/app/hooks/useMenuItems.ts b/app/hooks/useMenuItems.ts index d7633d5a..5076ceaf 100644 --- a/app/hooks/useMenuItems.ts +++ b/app/hooks/useMenuItems.ts @@ -27,6 +27,24 @@ const menuKeyToSlug: Record = { tools: 'tools', }; +/** + * Puts the challenge entry in the place of the offer entry: "Vos enjeux" + * replaces "Notre offre" once a challenge is published in the page language. + * Without one, the offer entry stays. The `/offer` route itself stays live. + */ +export function placeChallengeItem( + items: NavItem[], + challengeItem: NavItem | null, +): NavItem[] { + if (challengeItem === null) { + return items; + } + if (!items.some((item) => item.key === 'offer')) { + return [challengeItem, ...items]; + } + return items.map((item) => (item.key === 'offer' ? challengeItem : item)); +} + export function useMenuItems(): NavItem[] { const { t } = useTranslation('common'); const getLocalizedPath = useLocalizedPathname(); @@ -127,8 +145,7 @@ export function useMenuItems(): NavItem[] { }, ]; - return [ - ...(challengeItem ? [challengeItem] : []), + const items: NavItem[] = [ { key: 'offer', label: t('navigation.offer'), @@ -164,4 +181,6 @@ export function useMenuItems(): NavItem[] { isButton: true, }, ]; + + return placeChallengeItem(items, challengeItem); }