Private
Public Access
1
0

Fix gradient backgrounds being overridden by background-image property

The layout had `background: var(--color-page-bg); background-image: ...`
which meant that when --color-page-bg was a gradient (which sets
background-image via the shorthand), the subsequent background-image
declaration would reset it to none.

Fix: use `background` shorthand only via CSS classes (.layout-page-bg,
.layout-nav-bg), and handle uploaded background images via class-level
overrides in generateTenantCSS instead of CSS vars.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Catherine Renelle
2026-02-27 14:27:10 -05:00
parent 95ec8f30dd
commit ce5310e7a0
4 changed files with 40 additions and 13 deletions
+12
View File
@@ -28,6 +28,18 @@
} }
} }
.layout-page-bg {
background: var(--color-page-bg);
background-size: cover;
background-position: center;
}
.layout-nav-bg {
background: var(--color-nav-bg);
background-size: cover;
background-position: center;
}
.prose { .prose {
line-height: 1.6; line-height: 1.6;
} }
+10 -6
View File
@@ -92,18 +92,19 @@ export function generateTenantCSS(theme: TenantThemeData | null | undefined): st
} }
} }
// Handle background images // Handle background images — generate class-level overrides
const extraRules: string[] = [];
if (theme.lightPageBgImage) { if (theme.lightPageBgImage) {
lightVars.push(` --page-bg-image: url('${theme.lightPageBgImage}');`); extraRules.push(`.layout-page-bg { background-image: url('${theme.lightPageBgImage}'); }`);
} }
if (theme.lightNavBgImage) { if (theme.lightNavBgImage) {
lightVars.push(` --nav-bg-image: url('${theme.lightNavBgImage}');`); extraRules.push(`.layout-nav-bg { background-image: url('${theme.lightNavBgImage}'); }`);
} }
if (theme.darkPageBgImage) { if (theme.darkPageBgImage) {
darkVars.push(` --page-bg-image: url('${theme.darkPageBgImage}');`); extraRules.push(`html.dark .layout-page-bg { background-image: url('${theme.darkPageBgImage}'); }`);
} }
if (theme.darkNavBgImage) { if (theme.darkNavBgImage) {
darkVars.push(` --nav-bg-image: url('${theme.darkNavBgImage}');`); extraRules.push(`html.dark .layout-nav-bg { background-image: url('${theme.darkNavBgImage}'); }`);
} }
// Handle column/card opacity for backdrop-blur // Handle column/card opacity for backdrop-blur
@@ -120,7 +121,7 @@ export function generateTenantCSS(theme: TenantThemeData | null | undefined): st
darkVars.push(` --card-backdrop-blur: blur(8px);`); darkVars.push(` --card-backdrop-blur: blur(8px);`);
} }
if (lightVars.length === 0 && darkVars.length === 0) return ''; if (lightVars.length === 0 && darkVars.length === 0 && extraRules.length === 0) return '';
let css = '<style id="tenant-theme">\n'; let css = '<style id="tenant-theme">\n';
if (lightVars.length > 0) { if (lightVars.length > 0) {
@@ -129,6 +130,9 @@ export function generateTenantCSS(theme: TenantThemeData | null | undefined): st
if (darkVars.length > 0) { if (darkVars.length > 0) {
css += `html.dark {\n${darkVars.join('\n')}\n}\n`; css += `html.dark {\n${darkVars.join('\n')}\n}\n`;
} }
if (extraRules.length > 0) {
css += extraRules.join('\n') + '\n';
}
css += '</style>'; css += '</style>';
return css; return css;
+16 -5
View File
@@ -45,6 +45,7 @@ function hexToRgba(hex: string, opacity: number): string {
} }
const appliedVars: string[] = []; const appliedVars: string[] = [];
const appliedElements: { el: HTMLElement; prop: string }[] = [];
/** /**
* Applies theme preview by setting CSS vars on document.documentElement.style. * Applies theme preview by setting CSS vars on document.documentElement.style.
@@ -94,16 +95,22 @@ export function applyThemePreview(draft: TenantThemeData, mode: 'light' | 'dark'
} }
} }
// Handle bg images // Handle bg images — set directly on target elements
const pageBgImage = (draft as any)[pageBgImageField]; const pageBgImage = (draft as any)[pageBgImageField];
if (pageBgImage) { if (pageBgImage) {
el.style.setProperty('--page-bg-image', `url('${pageBgImage}')`); const pageEl = document.querySelector('.layout-page-bg') as HTMLElement;
appliedVars.push('--page-bg-image'); if (pageEl) {
pageEl.style.backgroundImage = `url('${pageBgImage}')`;
appliedElements.push({ el: pageEl, prop: 'background-image' });
}
} }
const navBgImage = (draft as any)[navBgImageField]; const navBgImage = (draft as any)[navBgImageField];
if (navBgImage) { if (navBgImage) {
el.style.setProperty('--nav-bg-image', `url('${navBgImage}')`); const navEl = document.querySelector('.layout-nav-bg') as HTMLElement;
appliedVars.push('--nav-bg-image'); if (navEl) {
navEl.style.backgroundImage = `url('${navBgImage}')`;
appliedElements.push({ el: navEl, prop: 'background-image' });
}
} }
} }
@@ -116,4 +123,8 @@ export function clearThemePreview() {
el.style.removeProperty(v); el.style.removeProperty(v);
} }
appliedVars.length = 0; appliedVars.length = 0;
for (const { el: targetEl, prop } of appliedElements) {
targetEl.style.removeProperty(prop);
}
appliedElements.length = 0;
} }
+2 -2
View File
@@ -24,8 +24,8 @@
}); });
</script> </script>
<div class="min-h-screen" style="background: var(--color-page-bg); background-image: var(--page-bg-image, none); background-size: cover; background-position: center;"> <div class="min-h-screen layout-page-bg">
<nav class="shadow-sm" style="background: var(--color-nav-bg); background-image: var(--nav-bg-image, none); background-size: cover; background-position: center;"> <nav class="shadow-sm layout-nav-bg">
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8"> <div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
<div class="flex h-14 items-center justify-between"> <div class="flex h-14 items-center justify-between">
<a href="/" class="flex items-center gap-2 text-white font-bold text-lg"> <a href="/" class="flex items-center gap-2 text-white font-bold text-lg">