Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubabrzy committed Sep 19, 2023
1 parent 5757de0 commit 06190ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/components/Accordion/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ type AccordionItemProps = {
summary: string;
open?: boolean;
highlight?: boolean;
id: string
id: string;
isHashEnabled?: boolean;
};

const AccordionItem = ({ summary, open, children, id }: AccordionItemProps) => {
const AccordionItem = ({
summary,
open,
children,
id,
isHashEnabled,
}: AccordionItemProps) => {
const detailsRef = useRef(null);
const location = useLocation();
const hashEnabled = location.pathname === '/faq'

const handleItemClick = () => {
document.querySelectorAll("details.accordion-item").forEach((item) => {
if (item !== detailsRef.current) {
item.removeAttribute("open");
}
});

if(!hashEnabled) {
if (!isHashEnabled) {
return;
}

Expand All @@ -33,7 +40,7 @@ const AccordionItem = ({ summary, open, children, id }: AccordionItemProps) => {
};

useEffect(() => {
if (decodeURI(location.hash) === `#${id}` && hashEnabled) {
if (decodeURI(location.hash) === `#${id}` && isHashEnabled) {
document.querySelectorAll("details.accordion-item").forEach((item) => {
if (item !== detailsRef.current) {
item.removeAttribute("open");
Expand Down
4 changes: 3 additions & 1 deletion src/pages/faq.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default function FAQ() {
<Accordion>
<MDXProvider
components={{
AccordionItem,
AccordionItem: (props) => (
<AccordionItem isHashEnabled {...props} />
),
a: (props) => (
<Link className="text-inherit underline" {...props} />
),
Expand Down

0 comments on commit 06190ca

Please sign in to comment.