fix(mobile-menu): use persistent store and move x-cloak to base layer for stability
All checks were successful
Deploy Theme / deploy (push) Successful in 13s

This commit is contained in:
2026-02-19 21:03:41 +01:00
parent 265cee9b97
commit ce531399f9
4 changed files with 22 additions and 18 deletions

View File

@@ -48,9 +48,9 @@ html[data-theme='light'] {
--text-tertiary: #7d5e31; --text-tertiary: #7d5e31;
} }
@layer base {
[x-cloak] { display: none !important; } [x-cloak] { display: none !important; }
@layer base {
body { body {
background-color: var(--bg-primary); background-color: var(--bg-primary);
color: var(--text-primary); color: var(--text-primary);

View File

@@ -2,23 +2,13 @@
<html lang="{{@site.lang}}" <html lang="{{@site.lang}}"
x-data="{ x-data="{
theme: localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'), theme: localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'),
mobileMenuOpen: false,
init() { init() {
$watch('theme', val => { $watch('theme', val => {
localStorage.setItem('theme', val); localStorage.setItem('theme', val);
document.documentElement.setAttribute('data-theme', val); document.documentElement.setAttribute('data-theme', val);
}); });
$watch('mobileMenuOpen', val => {
console.log('Mobile menu open state changed to:', val);
});
document.documentElement.setAttribute('data-theme', this.theme); document.documentElement.setAttribute('data-theme', this.theme);
document.documentElement.classList.remove('hidden'); document.documentElement.classList.remove('hidden');
// Close mobile menu on HTMX navigation
document.addEventListener('htmx:beforeRequest', () => {
console.log('HTMX beforeRequest: closing menu');
this.mobileMenuOpen = false;
});
} }
}" }"
:data-theme="theme" :data-theme="theme"
@@ -35,6 +25,20 @@
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script> <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script src="https://unpkg.com/htmx.org@2.0.0"></script> <script src="https://unpkg.com/htmx.org@2.0.0"></script>
<script>
document.addEventListener('alpine:init', () => {
Alpine.store('mobileMenu', {
open: false,
close() { this.open = false; },
openMenu() { this.open = true; }
});
});
document.addEventListener('htmx:beforeRequest', () => {
if (window.Alpine) Alpine.store('mobileMenu').close();
});
</script>
{{ghost_head}} {{ghost_head}}
</head> </head>
<body class="{{body_class}} font-sans antialiased"> <body class="{{body_class}} font-sans antialiased">

View File

@@ -22,7 +22,7 @@
</button> </button>
</nav> </nav>
<button @click.stop="mobileMenuOpen = true" class="md:hidden p-2 rounded-full bg-[var(--bg-secondary)] text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition-colors duration-200"> <button @click.stop="$store.mobileMenu.openMenu()" class="md:hidden p-2 rounded-full bg-[var(--bg-secondary)] text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition-colors duration-200">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" /> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" />
</svg> </svg>

View File

@@ -1,5 +1,5 @@
<div id="mobile-menu" <div id="mobile-menu"
x-show="mobileMenuOpen" x-show="$store.mobileMenu.open"
x-transition:enter="transition ease-out duration-300" x-transition:enter="transition ease-out duration-300"
x-transition:enter-start="-translate-x-full" x-transition:enter-start="-translate-x-full"
x-transition:enter-end="translate-x-0" x-transition:enter-end="translate-x-0"
@@ -7,13 +7,13 @@
x-transition:leave-start="translate-x-0" x-transition:leave-start="translate-x-0"
x-transition:leave-end="-translate-x-full" x-transition:leave-end="-translate-x-full"
class="fixed inset-0 z-50 bg-[var(--bg-primary)] flex flex-col md:hidden" class="fixed inset-0 z-50 bg-[var(--bg-primary)] flex flex-col md:hidden"
@click.away="mobileMenuOpen = false" @click.away="$store.mobileMenu.close()"
hx-boost="false" hx-boost="false"
x-cloak> x-cloak>
<!-- Mobile Menu Header --> <!-- Mobile Menu Header -->
<div class="flex justify-between items-center p-5 flex-none"> <div class="flex justify-between items-center p-5 flex-none">
<a href="{{@site.url}}" class="flex items-center text-[var(--text-primary)]" @click.stop="mobileMenuOpen = false"> <a href="{{@site.url}}" class="flex items-center text-[var(--text-primary)]" @click.stop="$store.mobileMenu.close()">
{{#if @site.logo}} {{#if @site.logo}}
<img src="{{@site.logo}}" alt="{{@site.title}}" class="h-10 w-auto site-logo"> <img src="{{@site.logo}}" alt="{{@site.title}}" class="h-10 w-auto site-logo">
{{else}} {{else}}
@@ -21,7 +21,7 @@
{{/if}} {{/if}}
<span class="ml-3 text-xl font-bold">{{@site.title}}</span> <span class="ml-3 text-xl font-bold">{{@site.title}}</span>
</a> </a>
<button @click.stop="mobileMenuOpen = false" class="p-2 rounded-full bg-[var(--bg-secondary)] text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition-colors duration-200"> <button @click.stop="$store.mobileMenu.close()" class="p-2 rounded-full bg-[var(--bg-secondary)] text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition-colors duration-200">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" /> <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg> </svg>
@@ -29,7 +29,7 @@
</div> </div>
<!-- Mobile Menu Navigation --> <!-- Mobile Menu Navigation -->
<nav class="flex-grow flex flex-col items-center justify-center p-10 overflow-y-auto" @click="mobileMenuOpen = false"> <nav class="flex-grow flex flex-col items-center justify-center p-10 overflow-y-auto" @click="$store.mobileMenu.close()">
<div class="w-full text-center"> <div class="w-full text-center">
{{navigation type="primary"}} {{navigation type="primary"}}
</div> </div>