Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit cc7982c

Browse files
authored
Merge pull request #5827 from SimonBrandner/show-drop-only-file
Show drop file UI only if dragging a file
2 parents 3c25979 + dacffdd commit cc7982c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/components/structures/RoomView.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,10 +1137,16 @@ export default class RoomView extends React.Component<IProps, IState> {
11371137
ev.stopPropagation();
11381138
ev.preventDefault();
11391139

1140-
this.setState({
1141-
dragCounter: this.state.dragCounter + 1,
1142-
draggingFile: true,
1143-
});
1140+
// We always increment the counter no matter the types, because dragging is
1141+
// still happening. If we didn't, the drag counter would get out of sync.
1142+
this.setState({dragCounter: this.state.dragCounter + 1});
1143+
1144+
// See:
1145+
// https://docs.w3cub.com/dom/datatransfer/types
1146+
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types#file
1147+
if (ev.dataTransfer.types.includes("Files") || ev.dataTransfer.types.includes("application/x-moz-file")) {
1148+
this.setState({draggingFile: true});
1149+
}
11441150
};
11451151

11461152
private onDragLeave = ev => {
@@ -1164,6 +1170,9 @@ export default class RoomView extends React.Component<IProps, IState> {
11641170

11651171
ev.dataTransfer.dropEffect = 'none';
11661172

1173+
// See:
1174+
// https://docs.w3cub.com/dom/datatransfer/types
1175+
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types#file
11671176
if (ev.dataTransfer.types.includes("Files") || ev.dataTransfer.types.includes("application/x-moz-file")) {
11681177
ev.dataTransfer.dropEffect = 'copy';
11691178
}

0 commit comments

Comments
 (0)