Skip to content

Commit a523506

Browse files
committed
Improve mobile menu to work without js
1 parent 03ccae5 commit a523506

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/components/MobileMenu.jsx

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createSignal } from "solid-js";
2-
import { A, useLocation } from "@solidjs/router";
1+
import { useLocation } from "@solidjs/router";
2+
import { A } from "@solidjs/router";
33
import {
44
BsHouseFill,
55
BsPeopleFill,
@@ -13,14 +13,17 @@ import { Logo } from "./Logo";
1313
export default function MobileMenu() {
1414
const location = useLocation();
1515
const isActive = (path) => location.pathname === path;
16-
const [isOpen, setIsOpen] = createSignal(false);
17-
18-
const toggleMenu = () => {
19-
setIsOpen(!isOpen());
20-
};
2116

2217
return (
2318
<div class="fixed top-0 left-0 right-0 z-50 md:hidden">
19+
{/* Checkbox for the toggle - placed at the top level */}
20+
<input
21+
type="checkbox"
22+
id="mobile-menu-toggle"
23+
class="hidden peer"
24+
aria-label="Toggle menu"
25+
/>
26+
2427
{/* Header with background */}
2528
<div class="glass !rounded-none !px-4 !py-2 flex justify-between items-center">
2629
{/* Logo on the left */}
@@ -30,27 +33,26 @@ export default function MobileMenu() {
3033
</div>
3134
</A>
3235

33-
{/* Burger Button on the right */}
34-
<button
35-
onClick={toggleMenu}
36-
class="text-white p-2"
36+
{/* Burger Button on the right - using checkbox hack */}
37+
<label
38+
for="mobile-menu-toggle"
39+
class="text-white p-2 cursor-pointer block"
3740
aria-label="Toggle menu"
3841
>
39-
{isOpen() ? <BsX size={30} /> : <BsList size={30} />}
40-
</button>
42+
<BsList size={30} class="peer-checked:hidden" />
43+
<BsX size={30} class="hidden peer-checked:block" />
44+
</label>
4145
</div>
4246

43-
{/* Mobile Menu Dropdown */}
44-
{isOpen() && (
45-
<div class="absolute top-full left-0 right-0 burger-menu">
46-
<div class="glass !p-4 !rounded-none">
47+
{/* Mobile Menu Dropdown - visible when checkbox is checked */}
48+
<div class="absolute top-full left-0 right-0 burger-menu hidden peer-checked:block">
49+
<div class="glass !p-4 !rounded-none">
4750
<nav class="flex flex-col space-y-4">
4851
{/* Home */}
4952
<A
5053
href="/"
5154
class={`text-white hover:text-white/80 transition-all duration-75 font-bold text-lg flex items-center justify-end gap-2 ${isActive('/') ? 'underline' : ''}`}
5255
aria-label="Home"
53-
onClick={() => setIsOpen(false)}
5456
>
5557
<BsHouseFill />
5658
Home
@@ -61,7 +63,6 @@ export default function MobileMenu() {
6163
href="/sponsorship"
6264
class={`text-white hover:text-white/80 transition-all duration-75 font-bold text-lg flex items-center justify-end gap-2 ${isActive('/sponsorship') ? 'underline' : ''}`}
6365
aria-label="Sponsorship"
64-
onClick={() => setIsOpen(false)}
6566
>
6667
<BiSolidHeartCircle />
6768
Sponsorship
@@ -72,7 +73,6 @@ export default function MobileMenu() {
7273
href="/hotels"
7374
class={`text-white hover:text-white/80 transition-all duration-75 font-bold text-lg flex items-center justify-end gap-2 ${isActive('/hotels') ? 'underline' : ''}`}
7475
aria-label="Hotels"
75-
onClick={() => setIsOpen(false)}
7676
>
7777
<FaSolidHotel />
7878
Hotels
@@ -83,15 +83,13 @@ export default function MobileMenu() {
8383
href="/organizers"
8484
class={`text-white hover:text-white/80 transition-all duration-75 font-bold text-lg flex items-center justify-end gap-2 ${isActive('/organizers') ? 'underline' : ''}`}
8585
aria-label="Organizers"
86-
onClick={() => setIsOpen(false)}
8786
>
8887
<BsPeopleFill />
8988
Organizers
9089
</A>
9190
</nav>
9291
</div>
9392
</div>
94-
)}
9593
</div>
9694
);
9795
}

0 commit comments

Comments
 (0)