From 774defd1841c63b0d2d2508d546068127b20cb93 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 3 Aug 2024 14:42:06 +0200 Subject: [PATCH] fix: image preview element styling issue --- src/lib/components/common/ImagePreview.svelte | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib/components/common/ImagePreview.svelte b/src/lib/components/common/ImagePreview.svelte index 16253b8a2..c1d1fef6b 100644 --- a/src/lib/components/common/ImagePreview.svelte +++ b/src/lib/components/common/ImagePreview.svelte @@ -7,6 +7,8 @@ let mounted = false; + let previewElement = null; + const downloadImage = (url, filename) => { fetch(url) .then((response) => response.blob()) @@ -34,14 +36,14 @@ mounted = true; }); - $: if (mounted) { - if (show) { - window.addEventListener('keydown', handleKeyDown); - document.body.style.overflow = 'hidden'; - } else { - window.removeEventListener('keydown', handleKeyDown); - document.body.style.overflow = 'unset'; - } + $: if (show && previewElement) { + document.body.appendChild(previewElement); + window.addEventListener('keydown', handleKeyDown); + document.body.style.overflow = 'hidden'; + } else if (previewElement) { + window.removeEventListener('keydown', handleKeyDown); + document.body.removeChild(previewElement); + document.body.style.overflow = 'unset'; } @@ -49,7 +51,8 @@