fixed no dismiss on nav bar

This commit is contained in:
Xanazf 2024-10-17 22:38:55 +03:00
parent 62b272c3b9
commit 48650545bd
Signed by: Xanazf
GPG key ID: 4E4A5AD1FB748427
3 changed files with 16 additions and 8 deletions

View file

@ -37,10 +37,11 @@ const NavComponent: Component<NavProps> = props => {
const handleClickOutside = (event: MouseEvent) => {
const isLink = "href" in (event.target || {});
const isInBody = document.body.contains(event.target as Node);
if (
isLink ||
(document.body.contains(event.target as Node) &&
!navRef.contains(event.target as Node))
!isInBody ||
(isInBody && !navRef.contains(event.target as Node))
) {
setOpen(false);
}
@ -70,11 +71,8 @@ const NavComponent: Component<NavProps> = props => {
ref={navRef!}
>
<div onclick={e => toggle(e)}>
{open() ? (
<MenuToX class="nav-icon" />
) : (
<XToMenu class="nav-icon" />
)}
<MenuToX class={`nav-icon ${open() ? "active" : ""}`} />
<XToMenu class={`nav-icon ${!open() ? "active" : ""}`} />
</div>
<div
id={open() ? "#qs_search" : ""}

View file

@ -47,7 +47,6 @@ const TableOfContents: Component<TOCProps> = props => {
});
createEffect(() => {
const tocRoot = document.getElementById("toc")!;
if (open()) {
window.addEventListener("click", handleClickOutside);
document.body.style.overflow = "hidden";

View file

@ -5,6 +5,17 @@
display: none;
}
.nav-icon {
opacity: 0;
position: absolute;
transition: opacity 0.6s;
}
.nav-icon.active {
opacity: 1;
position: relative;
}
.nav-toggle {
position: unset;
height: 24px;