fix(theme-common): allow details to not provide a summary (#7267)

This commit is contained in:
Joshua Chen 2022-04-30 01:33:28 +08:00 committed by GitHub
parent e053f39cf0
commit 41f53718c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View file

@ -13,9 +13,8 @@ export default function MDXDetails(props: Props): JSX.Element {
const items = React.Children.toArray(props.children) as ReactElement[];
// Split summary item from the rest to pass it as a separate prop to the
// Details theme component
const summary: ReactElement<ComponentProps<'summary'>> = items.find(
(item) => item?.props?.mdxType === 'summary',
)!;
const summary: ReactElement<ComponentProps<'summary'>> | undefined =
items.find((item) => item?.props?.mdxType === 'summary');
const children = <>{items.filter((item) => item !== summary)}</>;
return (

View file

@ -91,7 +91,7 @@ export function Details({
// setOpen(false);
}
}}>
{summary}
{summary || <summary>Details</summary>}
<Collapsible
lazy={false} // Content might matter for SEO in this case

View file

@ -175,3 +175,11 @@ Code tag + double pipe: <code>||</code>
![](/4/图片.png)
![](/4/docu.png)
## Details
<details>
Details without a summary
</details>