diff --git a/src/theme/MDXComponents/Details.tsx b/src/theme/MDXComponents/Details.tsx new file mode 100644 index 000000000..4b7aa98f9 --- /dev/null +++ b/src/theme/MDXComponents/Details.tsx @@ -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> => React.isValidElement(item) && item.type === 'summary', + ); + + const children = <>{items.filter((item) => item !== summary)}; + + return ( +
{ + if ((e.target as HTMLElement).tagName === 'A' && (e.target as HTMLElement).closest('summary')) { + e.stopPropagation(); + } + }} + summary={summary} + > + {children} +
+ ); +}