Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ function hasParent(node: HTMLElement | null, parent: HTMLElement): boolean {
}

export type DetailsProps = {
/** Summary is provided as props, including the wrapping `<summary>` tag */
summary?: ReactElement;
/**
* Summary is provided as props, optionally including the wrapping
* `<summary>` tag
*/
summary?: ReactElement | string;
} & ComponentProps<'details'>;

/**
Expand All @@ -54,6 +57,12 @@ export function Details({
// only after animation completes, otherwise close animations won't work
const [open, setOpen] = useState(props.open);

const summaryElement = React.isValidElement(summary) ? (
summary
) : (
<summary>{summary ?? 'Details'}</summary>
);

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
<details
Expand Down Expand Up @@ -91,8 +100,7 @@ export function Details({
// setOpen(false);
}
}}>
{/* eslint-disable-next-line @docusaurus/no-untranslated-text */}
{summary ?? <summary>Details</summary>}
{summaryElement}

<Collapsible
lazy={false} // Content might matter for SEO in this case
Expand Down
5 changes: 5 additions & 0 deletions website/_dogfooding/_pages tests/markdownPageTests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ Details without a summary

</details>

import Details from '@theme/Details';

<Details summary={'My Headline'}>Some Text</Details>
<Details>Some Text</Details>

This is a fragment:

<>Hello</>
Expand Down