Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,8 @@ 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 +54,16 @@ export function Details({
// only after animation completes, otherwise close animations won't work
const [open, setOpen] = useState(props.open);

let SummaryElement = null;

if (React.isValidElement(summary)) {
SummaryElement = summary;
} else if (typeof summary === 'string') {
SummaryElement = <summary>{summary}</summary>;
} else {
SummaryElement = <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 +101,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
12 changes: 12 additions & 0 deletions website/_dogfooding/_docs tests/details.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
slug: details.html
---

import Details from '@theme/Details';

# Testing Details component

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