From 44a07e04e2574b0aa82befa81460641c3a4d4e46 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Thu, 15 Jun 2023 20:59:39 +0530 Subject: [PATCH] Fixed file upload not triggering for same file selection refs https://github.com/TryGhost/Team/issues/3432 File upload component was not firing `onChange` when user attempts to upload the same again, which is a side-effect of `input` field behavior. This change resets the file input on every upload with a new key so that the upload always fires --- .../src/admin-x-ds/global/form/FileUpload.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ghost/admin-x-settings/src/admin-x-ds/global/form/FileUpload.tsx b/ghost/admin-x-settings/src/admin-x-ds/global/form/FileUpload.tsx index 692d1fed35..95987b98c7 100644 --- a/ghost/admin-x-settings/src/admin-x-ds/global/form/FileUpload.tsx +++ b/ghost/admin-x-settings/src/admin-x-ds/global/form/FileUpload.tsx @@ -1,4 +1,4 @@ -import React, {ChangeEvent} from 'react'; +import React, {ChangeEvent, useState} from 'react'; export interface FileUploadProps { id: string; @@ -15,16 +15,19 @@ export interface FileUploadProps { } const FileUpload: React.FC = ({id, onUpload, children, style, ...props}) => { + const [fileKey, setFileKey] = useState(Date.now()); + const handleFileChange = (event: ChangeEvent) => { const selectedFile = event.target.files?.[0]; if (selectedFile) { onUpload?.(selectedFile); } + setFileKey(Date.now()); }; return (