From eae35cb78dc78bee5b5bccb95231b6df8ff1115e Mon Sep 17 00:00:00 2001 From: Edmund Hung Date: Sun, 10 Mar 2024 19:32:18 +0100 Subject: [PATCH] chore: close details on location key change --- app/layout.tsx | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/layout.tsx b/app/layout.tsx index 176b225..95458a7 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,8 +1,8 @@ -import * as React from 'react'; import chevronUpIcon from '~/assets/chevron-up.svg'; import chevronRightIcon from '~/assets/chevron-right.svg'; import remixLetterLogo from '~/assets/remix-letter-light.svg'; import { Link, useLocation } from '@remix-run/react'; +import { Fragment, useLayoutEffect, useRef } from 'react'; export interface Menu { title: string; @@ -13,15 +13,28 @@ export interface Menu { } export function Breadcrumbs({ + locationKey, trails, children, }: { + locationKey: string; trails: string[]; children: React.ReactNode; }) { + const detailsRef = useRef(null); + + useLayoutEffect(() => { + if (detailsRef.current) { + detailsRef.current.open = false; + } + }, [locationKey]); + return ( <> -
+
{trails.map((trail, index) => ( - + {index > 0 ? ( / ) : null} {trail} - + ))}
@@ -72,7 +85,7 @@ export function MainNavigation({ menus }: { menus: Menu[] }) { return (
- +