Skip to content

Commit

Permalink
Put callback back
Browse files Browse the repository at this point in the history
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
  • Loading branch information
Josh-Cena committed Aug 12, 2021
1 parent 5c4d863 commit 6a9bde8
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions packages/docusaurus-theme-common/src/components/Details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,6 @@ const Details = ({summary, children, ...props}: DetailsProps): JSX.Element => {
// We use a separate prop because it must be set only after animation completes
// Otherwise close anim won't work
const [open, setOpen] = useState(props.open);
const toggle = (e: React.SyntheticEvent) => {
e.stopPropagation(); // For isolation of multiple nested details/summary
const target = e.target as HTMLElement;
const shouldToggle =
isInSummary(target) && hasParent(target, detailsRef.current!);
if (!shouldToggle) {
return;
}
e.preventDefault();
if (collapsed) {
setCollapsed(false);
setOpen(true);
} else {
setCollapsed(true);
// setOpen(false); // Don't do this, it breaks close animation!
}
};

return (
<details
Expand All @@ -79,7 +62,23 @@ const Details = ({summary, children, ...props}: DetailsProps): JSX.Element => {
e.preventDefault();
}
}}
onClick={toggle}>
onClick={(e) => {
e.stopPropagation(); // For isolation of multiple nested details/summary
const target = e.target as HTMLElement;
const shouldToggle =
isInSummary(target) && hasParent(target, detailsRef.current!);
if (!shouldToggle) {
return;
}
e.preventDefault();
if (collapsed) {
setCollapsed(false);
setOpen(true);
} else {
setCollapsed(true);
// setOpen(false); // Don't do this, it breaks close animation!
}
}}>
{summary}

<Collapsible
Expand Down

0 comments on commit 6a9bde8

Please sign in to comment.