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

View file

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

View file

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