mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 19:03:38 +02:00
fix(v2): prepend docsearch modal to body element (#4188)
This commit is contained in:
parent
b0e38d57df
commit
d6510b63ae
2 changed files with 12 additions and 1 deletions
|
@ -53,6 +53,7 @@ function DocSearch({contextualSearch, ...props}) {
|
|||
|
||||
const {withBaseUrl} = useBaseUrlUtils();
|
||||
const history = useHistory();
|
||||
const searchContainer = useRef(null);
|
||||
const searchButtonRef = useRef(null);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [initialQuery, setInitialQuery] = useState(null);
|
||||
|
@ -73,12 +74,18 @@ function DocSearch({contextualSearch, ...props}) {
|
|||
|
||||
const onOpen = useCallback(() => {
|
||||
importDocSearchModalIfNeeded().then(() => {
|
||||
searchContainer.current = document.createElement('div');
|
||||
document.body.insertBefore(
|
||||
searchContainer.current,
|
||||
document.body.firstChild,
|
||||
);
|
||||
setIsOpen(true);
|
||||
});
|
||||
}, [importDocSearchModalIfNeeded, setIsOpen]);
|
||||
|
||||
const onClose = useCallback(() => {
|
||||
setIsOpen(false);
|
||||
searchContainer.current.remove();
|
||||
}, [setIsOpen]);
|
||||
|
||||
const onInput = useCallback(
|
||||
|
@ -172,7 +179,7 @@ function DocSearch({contextualSearch, ...props}) {
|
|||
{...props}
|
||||
searchParameters={searchParameters}
|
||||
/>,
|
||||
document.body,
|
||||
searchContainer.current,
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -14,3 +14,7 @@
|
|||
transition: all var(--ifm-transition-fast)
|
||||
var(--ifm-transition-timing-default);
|
||||
}
|
||||
|
||||
.DocSearch-Container {
|
||||
z-index: calc(var(--ifm-z-index-fixed) + 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue