Skip to content

Commit

Permalink
fix(theme-common): allow details to not provide a summary (#7267)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena authored Apr 29, 2022
1 parent e053f39 commit 41f5371
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions website/_dogfooding/_pages tests/markdownPageTests.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,11 @@ Code tag + double pipe: <code>||</code>
![](/4/图片.png)

![](/4/docu.png)

## Details

<details>

Details without a summary

</details>

0 comments on commit 41f5371

Please sign in to comment.