Skip to content

Commit 360eada

Browse files
Fix version picker x overlay interaction (#1410)
1 parent b14bfa8 commit 360eada

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

components/utilities/search.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useEffect } from "react";
2+
import { createPortal } from "react-dom";
23
import classNames from "classnames";
34
import FocusTrap from "focus-trap-react";
45
import { useRouter, withRouter } from "next/router";
@@ -27,14 +28,7 @@ const Search = () => {
2728
if (e && e.currentTarget !== e.target) {
2829
return;
2930
}
30-
3131
setIsModalOpen(!isModalOpen);
32-
33-
if (document.body.style.overflow == "hidden") {
34-
document.body.style.overflow = "unset";
35-
} else {
36-
document.body.style.overflow = "hidden";
37-
}
3832
};
3933

4034
const focus = () => {
@@ -46,20 +40,17 @@ const Search = () => {
4640

4741
const searchClicked = () => {
4842
setIsModalOpen(true);
49-
document.body.style.overflow = "hidden";
5043
focus();
5144
};
5245

5346
const handleKey = (e) => {
5447
if (e.key === "k" && (e.ctrlKey || e.metaKey)) {
5548
e.preventDefault(); // prevent "Save Page" from getting triggered.
5649
setIsModalOpen(true);
57-
document.body.style.overflow = "hidden";
5850
focus();
5951
}
6052
if (e.key === "Escape") {
6153
setIsModalOpen(false);
62-
document.body.style.overflow = "unset";
6354
}
6455
if (isModalOpen === true) {
6556
const resultCount = document.querySelectorAll(".ais-Hits-item").length;
@@ -264,7 +255,10 @@ const Search = () => {
264255
<p className={styles.SearchText}>Search</p>
265256
{windowWidth > 1024 && <p className={styles.HotKey}>{hotkey}</p>}
266257
</section>
267-
{modal}
258+
{/* Render modal via portal to escape header's stacking context */}
259+
{typeof document !== "undefined" && modal
260+
? createPortal(modal, document.body)
261+
: null}
268262
{/* <SearchBox /> */}
269263
</section>
270264
);

components/utilities/search.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Modal */
22
.ModalContainer {
3-
@apply fixed w-screen h-screen top-0 left-0 flex items-center justify-center z-elevated;
3+
@apply fixed w-screen h-screen top-0 left-0 flex items-center justify-center z-overlay;
44
}
55

66
.Modal {

styles/globals.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
* Files: sideBar.module.css, image.module.css, refCard.module.css
2020
*
2121
* z-elevated (10) - Code blocks, search, floating nav, nav icons
22-
* Files: code.module.css, autofunction.module.css, search.module.css,
22+
* Files: code.module.css, autofunction.module.css,
2323
* floatingNav.module.css, navChild.module.css, componentSlider.module.css
2424
*
2525
* z-base (0) - Default layer, code line highlights
2626
*
27-
* z-modal (100) - Reserved for modals and dialogs (future use)
27+
* z-overlay (90) - Full-screen overlays behind modals
28+
* Files: search.module.css
29+
*
30+
* z-modal (100) - Reserved for modals and dialogs
2831
* ==========================================================================
2932
*/
3033

tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ module.exports = {
189189
sidebar: "20", // Sidebar, refcards, lightbox close button
190190
header: "30", // Header, lightbox overlay, chat sticky
191191
dropdown: "50", // Version selector, tooltips, dropdown menus
192+
overlay: "90", // Full-screen overlays (search modal backdrop)
192193
modal: "100", // Modals, dialogs (reserved for future use)
193194
},
194195

0 commit comments

Comments
 (0)