From a7862354423d63ce8ad930fd1bc68f4c140e6a8b Mon Sep 17 00:00:00 2001 From: jakubabrzy Date: Mon, 18 Sep 2023 16:15:35 +0200 Subject: [PATCH] clean hash from url after close of faq item --- src/components/Accordion/Item.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/Accordion/Item.tsx b/src/components/Accordion/Item.tsx index eb93913f..a8346f6f 100644 --- a/src/components/Accordion/Item.tsx +++ b/src/components/Accordion/Item.tsx @@ -19,7 +19,12 @@ const AccordionItem = ({ summary, open, children }: AccordionItemProps) => { } }); - window.location.replace(`${location.pathname}#${encodeURI(summary)}`); + if (decodeURI(location.hash) === `#${summary}`) { + // Hash at the end disables ability to open automaticaly first FAQ item + window.location.replace(`${location.pathname}#`); + } else { + window.location.replace(`${location.pathname}#${encodeURI(summary)}`); + } }; useEffect(() => {