Skip to content

Commit 6784b3f

Browse files
committed
Make collapsed Summary/Details searchable until it is fixed upstream
1 parent 93ceb36 commit 6784b3f

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/theme/Details/index.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, {useRef, type ReactNode} from 'react';
2+
import Details from '@theme-original/Details';
3+
import type DetailsType from '@theme/Details';
4+
import type {WrapperProps} from '@docusaurus/types';
5+
import styles from './styles.module.css';
6+
import clsx from 'clsx';
7+
8+
type Props = WrapperProps<typeof DetailsType>;
9+
10+
/**
11+
* Make collapsed Summary/Details searchable until it is fixed upstream
12+
* https://github.com/oasisprotocol/docs/issues/1568
13+
*/
14+
export default function DetailsWrapper(props: Props): ReactNode {
15+
return (
16+
<Details
17+
{...props}
18+
className={clsx(props.className, styles.makeSearchable)}
19+
onToggle={(e) => {
20+
// The browser natively toggles details element when a result is found
21+
// inside details. This workaround then toggles react component.
22+
const isToggledBySearchNotClick = e.newState === 'open' && e.currentTarget.getAttribute('data-collapsed') === 'true'
23+
if (isToggledBySearchNotClick) {
24+
e.currentTarget.querySelector('summary').click()
25+
}
26+
27+
props.onToggle?.(e)
28+
}}
29+
/>
30+
);
31+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.makeSearchable > div {
2+
display: block !important;
3+
}

0 commit comments

Comments
 (0)