File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ .makeSearchable > div {
2+ display : block !important ;
3+ }
You can’t perform that action at this time.
0 commit comments