Skip to content

Commit

Permalink
add functionality to share faq item
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubabrzy committed Sep 18, 2023
1 parent f7f9c51 commit 963912a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/components/Accordion/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useRef } from "react";
import { useLocation } from "@docusaurus/router";
import React, { useEffect, useRef } from "react";

type AccordionItemProps = {
children: React.ReactNode;
Expand All @@ -9,15 +10,30 @@ type AccordionItemProps = {

const AccordionItem = ({ summary, open, children }: AccordionItemProps) => {
const detailsRef = useRef(null);
const location = useLocation();

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

window.location.replace(`${location.pathname}#${encodeURI(summary)}`);
};

useEffect(() => {
if (decodeURI(location.hash) === `#${summary}`) {
document.querySelectorAll("details.accordion-item").forEach((item) => {
if (item !== detailsRef.current) {
item.removeAttribute("open");
} else {
item.setAttribute("open", "true");
}
});
}
}, []);

return (
<details
ref={detailsRef}
Expand Down

0 comments on commit 963912a

Please sign in to comment.