Fix navbar no longer sticking to the top of the viewport

Wrapping the header in an extra <div className="dark"> (to force the
always-dark navbar look from the last change) broke its sticky
positioning - it stayed pinned in place instead of scrolling normally
and sticking to the top edge.

Removes that wrapper entirely and instead hardcodes the header's own
"dark" Tailwind values directly (no dark: prefix, no conditional on the
real theme) for the header background/border, hamburger button, admin
icon, and the navbar's own language dropdown - all previously toggled via
a dark: variant that depended on an ancestor carrying the "dark" class.
The logo now always renders the dark-mode wordmark image directly rather
than swapping between two images via dark:hidden/dark:block.

ThemeToggle.jsx gained an opt-in forceDark prop for this one case, so its
other usages (admin dashboard) keep following the real theme as before -
only the navbar's copy of the button is pinned to look dark, its click
behavior (toggling the site's actual theme) is unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Maaxxs 2026-09-10 03:06:22 +02:00
parent 260cd0700e
commit ed0d18b9c3
6 changed files with 86 additions and 83 deletions

View file

@ -6,7 +6,6 @@ import DynamicIcon from './DynamicIcon.jsx';
import { useAuth } from '../context/AuthContext.jsx';
import { useSiteSettings } from '../context/SiteSettingsContext.jsx';
import { useLanguage } from '../context/LanguageContext.jsx';
import logo from '../assets/logo.png';
import logoDark from '../assets/logo-dark.png';
const SHOP_URL = 'https://www.audio4cars.de/';
@ -76,9 +75,9 @@ function LanguageSwitcher({ overHero = false }) {
aria-haspopup="listbox"
aria-expanded={isOpen}
aria-label={t('languageToggle.label')}
className={`flex items-center gap-1 rounded-full p-1.5 transition ${overHero ? 'hover:bg-white/10' : 'hover:bg-neutral-100 dark:hover:bg-neutral-800'}`}
className={`flex items-center gap-1 rounded-full p-1.5 transition ${overHero ? 'hover:bg-white/10' : 'hover:bg-neutral-800'}`}
>
<span className={`block h-4 w-6 shrink-0 overflow-hidden rounded-[3px] ring-1 ${overHero ? 'ring-white/50' : 'ring-neutral-300 dark:ring-neutral-600'}`}>
<span className={`block h-4 w-6 shrink-0 overflow-hidden rounded-[3px] ring-1 ${overHero ? 'ring-white/50' : 'ring-neutral-600'}`}>
<current.Flag className="h-full w-full" />
</span>
<svg
@ -92,7 +91,7 @@ function LanguageSwitcher({ overHero = false }) {
</button>
{isOpen && (
<div role="listbox" className="absolute right-0 z-50 mt-2 min-w-[9rem] overflow-hidden rounded-lg border border-neutral-200 bg-white py-1 shadow-lg dark:border-neutral-700 dark:bg-neutral-900">
<div role="listbox" className="absolute right-0 z-50 mt-2 min-w-[9rem] overflow-hidden rounded-lg border border-neutral-700 bg-neutral-900 py-1 shadow-lg">
{LANGUAGE_OPTIONS.map((opt) => (
<button
key={opt.code}
@ -103,11 +102,11 @@ function LanguageSwitcher({ overHero = false }) {
setLanguage(opt.code);
setIsOpen(false);
}}
className={`flex w-full items-center gap-2 px-3 py-2 text-left text-sm transition hover:bg-neutral-100 dark:hover:bg-neutral-800 ${
opt.code === language ? 'font-semibold text-brand-600 dark:text-brand-400' : 'text-neutral-700 dark:text-neutral-200'
className={`flex w-full items-center gap-2 px-3 py-2 text-left text-sm transition hover:bg-neutral-800 ${
opt.code === language ? 'font-semibold text-brand-400' : 'text-neutral-200'
}`}
>
<span className="block h-4 w-6 shrink-0 overflow-hidden rounded-[3px] ring-1 ring-neutral-300 dark:ring-neutral-600">
<span className="block h-4 w-6 shrink-0 overflow-hidden rounded-[3px] ring-1 ring-neutral-600">
<opt.Flag className="h-full w-full" />
</span>
{opt.label}
@ -124,7 +123,7 @@ export default function Navbar() {
const [mounted, setMounted] = useState(false);
const [menuVisible, setMenuVisible] = useState(false);
const { user } = useAuth();
const { phone, whatsapp, logo_path: logoPath, logo_dark_path: logoDarkPath } = useSiteSettings();
const { phone, whatsapp, logo_dark_path: logoDarkPath } = useSiteSettings();
const { t } = useLanguage();
const totalItems = whatsapp ? 8 : 7;
const location = useLocation();
@ -183,7 +182,7 @@ export default function Navbar() {
aria-label={t('nav.adminPanel')}
title={t('nav.adminPanel')}
className={`rounded-full p-2 transition ${
transparent ? 'text-white hover:bg-white/10' : 'text-neutral-600 hover:bg-neutral-100 dark:text-neutral-300 dark:hover:bg-neutral-800'
transparent ? 'text-white hover:bg-white/10' : 'text-neutral-300 hover:bg-neutral-800'
}`}
>
<DynamicIcon name="layout-dashboard" className="h-5 w-5" />
@ -191,24 +190,23 @@ export default function Navbar() {
);
return (
// "dark" hier erzwungen (nicht vom eigentlichen Seiten-Theme abhaengig) - Kundenwunsch:
// die Navbar soll immer im Dark-Theme bleiben, unabhaengig vom Light-/Dark-Mode-Toggle
// des Besuchers. Alle dark:-Utilities in diesem Bereich greifen dadurch immer.
<div className="dark">
<header
className={`sticky top-0 z-30 border-b transition-colors duration-300 ${
transparent
? 'border-transparent bg-transparent'
: 'border-neutral-200 bg-white/90 backdrop-blur dark:border-neutral-800 dark:bg-neutral-950/90'
}`}
>
// Die Hintergrund-/Text-/Rahmenfarben hier sind bewusst die "dunklen" Werte fest verdrahtet
// statt per dark:-Utility bedingt (Kundenwunsch: die Navbar soll immer im Dark-Theme
// bleiben, unabhaengig vom Light-/Dark-Mode-Toggle des Besuchers).
<header
className={`sticky top-0 z-30 border-b transition-colors duration-300 ${
transparent
? 'border-transparent bg-transparent'
: 'border-neutral-800 bg-neutral-950/90 backdrop-blur'
}`}
>
<div className="mx-auto grid max-w-6xl grid-cols-[1fr_auto_1fr] items-center gap-3 px-4 py-3 sm:px-6">
<div className="flex items-center justify-self-start">
<button
onClick={() => setOpen(true)}
aria-label={t('nav.openMenu')}
className={`rounded-md p-2 transition ${
transparent ? 'text-white hover:bg-white/10' : 'text-neutral-600 hover:bg-neutral-100 dark:text-neutral-300 dark:hover:bg-neutral-800'
transparent ? 'text-white hover:bg-white/10' : 'text-neutral-300 hover:bg-neutral-800'
}`}
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" className="h-6 w-6">
@ -217,17 +215,16 @@ export default function Navbar() {
</button>
</div>
{/* Im Dark Mode eigene Logo-Variante mit weisser Wortmarke statt weissem
Chip hinter dem Logo (Kundenwunsch). */}
{/* Immer die Dark-Mode-Logovariante (weisse Wortmarke) - passend zur immer dunklen
Navbar, unabhaengig vom Light-/Dark-Mode-Toggle des Besuchers. */}
<Link to="/" className="flex items-center justify-self-center rounded-lg px-2 py-1">
<img src={logoPath || logo} alt="HifiPlanet" className="h-14 w-auto dark:hidden sm:h-16" />
<img src={logoDarkPath || logoDark} alt="HifiPlanet" className="hidden h-14 w-auto dark:block sm:h-16" />
<img src={logoDarkPath || logoDark} alt="HifiPlanet" className="h-14 w-auto sm:h-16" />
</Link>
<div className="flex items-center justify-self-end gap-1">
{AdminIcon}
{!open && <LanguageSwitcher overHero={transparent} />}
<ThemeToggle overHero={transparent} />
<ThemeToggle overHero={transparent} forceDark />
</div>
</div>
@ -296,7 +293,6 @@ export default function Navbar() {
</div>,
document.body
)}
</header>
</div>
</header>
);
}

View file

@ -1,16 +1,23 @@
import { useTheme } from '../context/ThemeContext.jsx';
import { useLanguage } from '../context/LanguageContext.jsx';
export default function ThemeToggle({ overHero = false }) {
export default function ThemeToggle({ overHero = false, forceDark = false }) {
const { theme, toggleTheme } = useTheme();
const { t } = useLanguage();
// forceDark: fuer Stellen wie die Navbar, deren eigene Optik immer dunkel bleiben soll,
// unabhaengig vom echten Light-/Dark-Mode des Besuchers - der Button steuert diesen weiterhin
// fuer den Rest der Seite, sieht dabei aber selbst immer "dunkel" aus.
return (
<button
onClick={toggleTheme}
aria-label={t('themeToggle.label')}
className={`rounded-full p-2 transition ${
overHero ? 'text-white hover:bg-white/10' : 'text-neutral-600 hover:bg-neutral-100 dark:text-neutral-300 dark:hover:bg-neutral-800'
overHero
? 'text-white hover:bg-white/10'
: forceDark
? 'text-neutral-300 hover:bg-neutral-800'
: 'text-neutral-600 hover:bg-neutral-100 dark:text-neutral-300 dark:hover:bg-neutral-800'
}`}
>
{theme === 'dark' ? (

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -43,9 +43,9 @@
"sameAs": ["https://www.youtube.com/@hifiplanet2812"]
}
</script>
<script type="module" crossorigin src="/assets/index-Bcw7aoHB.js"></script>
<script type="module" crossorigin src="/assets/index-D4_C7pxq.js"></script>
<link rel="modulepreload" crossorigin href="/assets/lucide-icons-Cg2IxtAO.js">
<link rel="stylesheet" crossorigin href="/assets/index-fn7vJl0-.css">
<link rel="stylesheet" crossorigin href="/assets/index-lUKoqEad.css">
</head>
<body class="bg-white text-slate-900 dark:bg-slate-950 dark:text-slate-100">
<div id="root"></div>