mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-20 10:08:17 +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 = {
|
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'>;
|
} & ComponentProps<'details'>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,6 +57,12 @@ export function Details({
|
||||||
// only after animation completes, otherwise close animations won't work
|
// only after animation completes, otherwise close animations won't work
|
||||||
const [open, setOpen] = useState(props.open);
|
const [open, setOpen] = useState(props.open);
|
||||||
|
|
||||||
|
const summaryElement = React.isValidElement(summary) ? (
|
||||||
|
summary
|
||||||
|
) : (
|
||||||
|
<summary>{summary ?? 'Details'}</summary>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
|
||||||
<details
|
<details
|
||||||
|
@ -91,8 +100,7 @@ export function Details({
|
||||||
// setOpen(false);
|
// setOpen(false);
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
{/* eslint-disable-next-line @docusaurus/no-untranslated-text */}
|
{summaryElement}
|
||||||
{summary ?? <summary>Details</summary>}
|
|
||||||
|
|
||||||
<Collapsible
|
<Collapsible
|
||||||
lazy={false} // Content might matter for SEO in this case
|
lazy={false} // Content might matter for SEO in this case
|
||||||
|
|
|
@ -204,6 +204,11 @@ Details without a summary
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
import Details from '@theme/Details';
|
||||||
|
|
||||||
|
<Details summary={'My Headline'}>Some Text</Details>
|
||||||
|
<Details>Some Text</Details>
|
||||||
|
|
||||||
This is a fragment:
|
This is a fragment:
|
||||||
|
|
||||||
<>Hello</>
|
<>Hello</>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue