From 56a493f4ab77b9d771aad24d75beae2aea8b3efb Mon Sep 17 00:00:00 2001 From: Mike <36415632+Mike-Heneghan@users.noreply.github.com> Date: Mon, 20 Nov 2023 09:18:31 +0000 Subject: [PATCH] fix: repeated label removed from file on change click bug (#2443) - When the modal was rendered it was incorrectly updating the fileList as the previousTags variable was undefined. - The update function for each SelectMultiple would set the file it controlled as the only file with that label - 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) => {