Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions src/theme/Details/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, {useRef, type ReactNode} from 'react';
import Details from '@theme-original/Details';
import type DetailsType from '@theme/Details';
import type {WrapperProps} from '@docusaurus/types';
import styles from './styles.module.css';
import clsx from 'clsx';

type Props = WrapperProps<typeof DetailsType>;

/**
* Make collapsed Summary/Details searchable until it is fixed upstream
* https://github.com/oasisprotocol/docs/issues/1568
*/
export default function DetailsWrapper(props: Props): ReactNode {
return (
<Details
{...props}
className={clsx(props.className, styles.makeSearchable)}
onToggle={(e) => {
// The browser natively toggles details element when a result is found
// inside details. This workaround then toggles react component.
const isToggledBySearchNotClick = e.newState === 'open' && e.currentTarget.getAttribute('data-collapsed') === 'true'
if (isToggledBySearchNotClick) {
e.currentTarget.querySelector('summary').click()
}

props.onToggle?.(e)
}}
/>
);
}
3 changes: 3 additions & 0 deletions src/theme/Details/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.makeSearchable > div {
display: block !important;
}