mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-19 01:28:38 +02:00
feat(theme-common): allow passing a string for details summary (#8656)
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
parent
5edd594613
commit
533777cf2b
2 changed files with 17 additions and 4 deletions
|
@ -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'>;
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue