Skip to content

Commit

Permalink
fix(openfga): allow nav link in accordion
Browse files Browse the repository at this point in the history
  • Loading branch information
ttrzeng committed Jan 3, 2025
1 parent 3761481 commit f16676c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/theme/MDXComponents/Details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { type ComponentProps, type ReactElement } from 'react';
import Details from '@theme/Details';
import type { Props } from '@theme/MDXComponents/Details';

export default function MDXDetails(props: Props): JSX.Element {
const items = React.Children.toArray(props.children);

const summary = items.find(
(item): item is ReactElement<ComponentProps<'summary'>> => React.isValidElement(item) && item.type === 'summary',
);

const children = <>{items.filter((item) => item !== summary)}</>;

return (
<Details
{...props}
onClickCapture={(e) => {
if ((e.target as HTMLElement).tagName === 'A' && (e.target as HTMLElement).closest('summary')) {
e.stopPropagation();
}
}}
summary={summary}
>
{children}
</Details>
);
}

0 comments on commit f16676c

Please sign in to comment.