mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-07 13:22:26 +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 {withBaseUrl} = useBaseUrlUtils();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const searchContainer = useRef(null);
|
||||||
const searchButtonRef = useRef(null);
|
const searchButtonRef = useRef(null);
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [initialQuery, setInitialQuery] = useState(null);
|
const [initialQuery, setInitialQuery] = useState(null);
|
||||||
|
@ -73,12 +74,18 @@ function DocSearch({contextualSearch, ...props}) {
|
||||||
|
|
||||||
const onOpen = useCallback(() => {
|
const onOpen = useCallback(() => {
|
||||||
importDocSearchModalIfNeeded().then(() => {
|
importDocSearchModalIfNeeded().then(() => {
|
||||||
|
searchContainer.current = document.createElement('div');
|
||||||
|
document.body.insertBefore(
|
||||||
|
searchContainer.current,
|
||||||
|
document.body.firstChild,
|
||||||
|
);
|
||||||
setIsOpen(true);
|
setIsOpen(true);
|
||||||
});
|
});
|
||||||
}, [importDocSearchModalIfNeeded, setIsOpen]);
|
}, [importDocSearchModalIfNeeded, setIsOpen]);
|
||||||
|
|
||||||
const onClose = useCallback(() => {
|
const onClose = useCallback(() => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
|
searchContainer.current.remove();
|
||||||
}, [setIsOpen]);
|
}, [setIsOpen]);
|
||||||
|
|
||||||
const onInput = useCallback(
|
const onInput = useCallback(
|
||||||
|
@ -172,7 +179,7 @@ function DocSearch({contextualSearch, ...props}) {
|
||||||
{...props}
|
{...props}
|
||||||
searchParameters={searchParameters}
|
searchParameters={searchParameters}
|
||||||
/>,
|
/>,
|
||||||
document.body,
|
searchContainer.current,
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,3 +14,7 @@
|
||||||
transition: all var(--ifm-transition-fast)
|
transition: all var(--ifm-transition-fast)
|
||||||
var(--ifm-transition-timing-default);
|
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