Fix: Keep file input in DOM during print area editing

Changed PhotoPrintAreaField to use CSS display:none instead of conditional rendering
to hide the file input when the print area editor is open. This prevents the file
input element from being removed from the DOM, which was causing the selected file
to be lost before form submission.

The issue occurred when:
1. User selected an image file
2. Preview loaded and print area editor opened (showPrintAreaEditor = true)
3. React conditionally removed the file input from the DOM
4. Form submission lost the file data because the input no longer existed

Now the file input stays in the DOM (just hidden), so the file data persists
through form submission.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Andymick
2026-07-20 20:18:24 +01:00
co-authored by Claude Haiku 4.5
parent f2aed12fb6
commit 487afb7a91
2 changed files with 43 additions and 44 deletions
+42 -44
View File
@@ -110,51 +110,49 @@ export default function PhotoPrintAreaField({
</div>
)}
{!currentImageUrl || !showPrintAreaEditor ? (
<>
<input
ref={fileInputRef}
id={fieldName}
name={fieldName}
type="file"
accept="image/*"
onChange={handleFileChange}
className="w-full border border-line bg-paper px-3 py-2 text-sm"
/>
{variant === 'front' ? (
<p className="mt-1 text-xs text-muted">
Uploading a real photo replaces the illustration everywhere this product is shown. One
tradeoff: the color swatches below can no longer recolor a photo the way they recolor the
illustration they&apos;ll still be saved with each order, but the picture itself stays
fixed. Leave this blank to keep using the illustration (which does recolor live).
</p>
) : (
<p className="mt-1 text-xs text-muted">
If set, customers get a Front/Back toggle and can add a separate design to the back
drag a print-area box below just like the front.
</p>
)}
<div style={{ display: showPrintAreaEditor && currentImageUrl ? 'none' : 'block' }}>
<input
ref={fileInputRef}
id={fieldName}
name={fieldName}
type="file"
accept="image/*"
onChange={handleFileChange}
className="w-full border border-line bg-paper px-3 py-2 text-sm"
/>
{variant === 'front' ? (
<p className="mt-1 text-xs text-muted">
Uploading a real photo replaces the illustration everywhere this product is shown. One
tradeoff: the color swatches below can no longer recolor a photo the way they recolor the
illustration they&apos;ll still be saved with each order, but the picture itself stays
fixed. Leave this blank to keep using the illustration (which does recolor live).
</p>
) : (
<p className="mt-1 text-xs text-muted">
If set, customers get a Front/Back toggle and can add a separate design to the back
drag a print-area box below just like the front.
</p>
)}
{currentImageUrl && !showPrintAreaEditor && (
<div className="mt-3 flex gap-2">
<button
type="button"
onClick={() => setShowPrintAreaEditor(true)}
className="text-sm text-clay hover:text-clay-dark font-medium"
>
Modify print area
</button>
<button
type="button"
onClick={handleClearFile}
className="text-sm text-splash-pink hover:text-splash-pink-dark font-medium"
>
Remove
</button>
</div>
)}
</>
) : null}
{currentImageUrl && !showPrintAreaEditor && (
<div className="mt-3 flex gap-2">
<button
type="button"
onClick={() => setShowPrintAreaEditor(true)}
className="text-sm text-clay hover:text-clay-dark font-medium"
>
Modify print area
</button>
<button
type="button"
onClick={handleClearFile}
className="text-sm text-splash-pink hover:text-splash-pink-dark font-medium"
>
Remove
</button>
</div>
)}
</div>
{currentImageUrl && showPrintAreaEditor && (
<div className="mt-4">