From ac2895fdb44a8327ffd9f2661ce75f399bbace64 Mon Sep 17 00:00:00 2001 From: Mike Heneghan Date: Fri, 17 Nov 2023 17:02:43 +0000 Subject: [PATCH] fix: repeated label removed from file on change click bug - When the modal was rendered it was incorrectly updating the fileList as the previousTags variable was undefined. - The update function only ever applies a tag to a single file so the second file was not being tagged. - Set the previousTags to the last state or the initialTags on first render - Updates are checked but an update isn't applied as the previousTags = intialTags --- .../src/@planx/components/FileUploadAndLabel/Modal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Modal.tsx b/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Modal.tsx index b37bd17869..4afb33cf5b 100644 --- a/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Modal.tsx +++ b/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Modal.tsx @@ -147,7 +147,7 @@ const SelectMultiple = (props: SelectMultipleProps) => { const initialTags = getTagsForSlot(uploadedFile.id, fileList); const [tags, setTags] = useState(initialTags); - const previousTags = usePrevious(tags); + const previousTags = usePrevious(tags) || initialTags; const [open, setOpen] = React.useState(false); const handleChange = (event: SelectChangeEvent) => {