diff --git a/packages/docusaurus-theme-common/src/components/Details/index.tsx b/packages/docusaurus-theme-common/src/components/Details/index.tsx index 19952166bc59..0876cf9b94d3 100644 --- a/packages/docusaurus-theme-common/src/components/Details/index.tsx +++ b/packages/docusaurus-theme-common/src/components/Details/index.tsx @@ -31,8 +31,11 @@ function hasParent(node: HTMLElement | null, parent: HTMLElement): boolean { } export type DetailsProps = { - /** Summary is provided as props, including the wrapping `` tag */ - summary?: ReactElement; + /** + * Summary is provided as props, optionally including the wrapping + * `` tag + */ + summary?: ReactElement | string; } & ComponentProps<'details'>; /** @@ -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 ?? 'Details'} + ); + return ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
- {/* eslint-disable-next-line @docusaurus/no-untranslated-text */} - {summary ?? Details} + {summaryElement} +import Details from '@theme/Details'; + +
Some Text
+
Some Text
+ This is a fragment: <>Hello