diff --git a/CHANGELOG.md b/CHANGELOG.md index afc846f7a6..50f26b434f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/ - Fixed math parsing that could cause Web Chat to hang when processing certain LaTeX expressions, in PR [#5377](https://github.com/microsoft/BotFramework-WebChat/pull/5377), by [@OEvgeny](https://github.com/OEvgeny) - Fixed long math formula should be scrollable, in PR [#5380](https://github.com/microsoft/BotFramework-WebChat/pull/5380), by [@compulim](https://github.com/compulim) - Fixed [#4948](https://github.com/microsoft/BotFramework-WebChat/issues/4948). Microphone should stop after initial silence, in PR [#5385](https://github.com/microsoft/BotFramework-WebChat/pull/5385) +- Fixed [#5390](https://github.com/microsoft/BotFramework-WebChat/issues/5390). Fixed drop zone remaining visible when file is dropped outside of the zone, in PR [#5394](https://github.com/microsoft/BotFramework-WebChat/pull/5394), by [@OEvgeny](https://github.com/OEvgeny) # Removed diff --git a/__tests__/__image_snapshots__/html/drag-and-drop-upload-js-fluent-theme-applied-drag-and-drop-upload-4-snap.png b/__tests__/__image_snapshots__/html/drag-and-drop-upload-js-fluent-theme-applied-drag-and-drop-upload-4-snap.png new file mode 100644 index 0000000000..5e52507bf7 Binary files /dev/null and b/__tests__/__image_snapshots__/html/drag-and-drop-upload-js-fluent-theme-applied-drag-and-drop-upload-4-snap.png differ diff --git a/__tests__/__image_snapshots__/html/drag-and-drop-upload-js-fluent-theme-applied-drag-and-drop-upload-5-snap.png b/__tests__/__image_snapshots__/html/drag-and-drop-upload-js-fluent-theme-applied-drag-and-drop-upload-5-snap.png new file mode 100644 index 0000000000..25170920f0 Binary files /dev/null and b/__tests__/__image_snapshots__/html/drag-and-drop-upload-js-fluent-theme-applied-drag-and-drop-upload-5-snap.png differ diff --git a/__tests__/html/fluentTheme/dragAndDrop.upload.html b/__tests__/html/fluentTheme/dragAndDrop.upload.html index d5a1f5d3f9..d00310302b 100644 --- a/__tests__/html/fluentTheme/dragAndDrop.upload.html +++ b/__tests__/html/fluentTheme/dragAndDrop.upload.html @@ -46,9 +46,11 @@ dataTransfer.items.add(new File([new ArrayBuffer(100)], 'simple.txt')); // WHEN: Dragging a file into document. - const dragEnterDocumentEvent = new DragEvent('dragenter', { dataTransfer }); - - dragEnterDocumentEvent.initEvent('dragenter', true, true); + const dragEnterDocumentEvent = new DragEvent('dragenter', { + bubbles: true, + cancelable: true, + dataTransfer + }); document.dispatchEvent(dragEnterDocumentEvent); @@ -56,26 +58,54 @@ await host.snapshot(); // WHEN: Dragging into the drop zone. - const dragEnterDropZoneEvent = new DragEvent('dragenter', { dataTransfer }); - - dragEnterDropZoneEvent.initEvent('dragenter', true, true); + const dragEnterDropZoneEvent = new DragEvent('dragenter', { + bubbles: true, + cancelable: true, + dataTransfer + }); document .querySelector(`[data-testid="${WebChat.testIds['sendBoxDropZone']}"]`) .dispatchEvent(dragEnterDropZoneEvent); - // THEN: Should render the drop zone. + // THEN: Should render element dropped. await host.snapshot(); // WHEN: Dropping into the drop zone. - const dropEvent = new DragEvent('drop', { dataTransfer }); - - dropEvent.initEvent('drop', true, true); + const dropEvent = new DragEvent('drop', { + bubbles: true, + cancelable: true, + dataTransfer + }); document.querySelector(`[data-testid="${WebChat.testIds['sendBoxDropZone']}"]`).dispatchEvent(dropEvent); // THEN: Should render the drop zone. await host.snapshot(); + + // WHEN: Dragging a file into document. + const dragEnterDocumentEvent1 = new DragEvent('dragenter', { + bubbles: true, + cancelable: true, + dataTransfer + }); + + document.dispatchEvent(dragEnterDocumentEvent1); + + // THEN: Should render the drop zone. + await host.snapshot(); + + // WHEN: Dropping out of the drop zone. + const dropEvent1 = new DragEvent('drop', { + bubbles: true, + cancelable: true, + dataTransfer + }); + + document.body.dispatchEvent(dropEvent1); + + // THEN: Should render single element dropped. + await host.snapshot(); }); diff --git a/packages/fluent-theme/src/components/dropZone/DropZone.tsx b/packages/fluent-theme/src/components/dropZone/DropZone.tsx index d39300d491..31aef8f468 100644 --- a/packages/fluent-theme/src/components/dropZone/DropZone.tsx +++ b/packages/fluent-theme/src/components/dropZone/DropZone.tsx @@ -67,14 +67,22 @@ const DropZone = (props: { readonly onFilesAdded: (files: File[]) => void }) => setDropZoneState(false); }; - document.addEventListener('dragenter', handleDragEnter, false); - document.addEventListener('dragleave', handleDragLeave, false); - document.addEventListener('dragend', handleDragEnd, false); + const handleDocumentDrop = (event: DragEvent) => { + if (!dropZoneRef.current?.contains(event.target as Node)) { + handleDragEnd(); + } + }; + + document.addEventListener('dragenter', handleDragEnter); + document.addEventListener('dragleave', handleDragLeave); + document.addEventListener('dragend', handleDragEnd); + document.addEventListener('drop', handleDocumentDrop); return () => { document.removeEventListener('dragenter', handleDragEnter); document.removeEventListener('dragleave', handleDragLeave); document.removeEventListener('dragend', handleDragEnd); + document.removeEventListener('drop', handleDocumentDrop); }; }, [setDropZoneState]);