Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File drop on specific HTML elements #3063

Closed
probablykasper opened this issue Dec 13, 2021 · 3 comments · Fixed by #7601
Closed

File drop on specific HTML elements #3063

probablykasper opened this issue Dec 13, 2021 · 3 comments · Fixed by #7601

Comments

@probablykasper
Copy link
Member

Is your feature request related to a problem? Please describe.
There's no easy way to handle file drops on specific elements yet. When you're dragging a file, JS events like mousemove stop emitting, so you can't tell where the cursor is (at least for me on macOS).

Describe the solution you'd like
The best solution would be for the native drag-and-drop API to work. Not sure what was preventing that from working?

Alternatively, tauri://file-drop-hover can include the mouse position and be spammed whenever the mouse moves. In JS, you could handle it like this:

import { event } from '@tauri-apps/api';

const dropzoneElement = document.querySelector(/* ... */);

event.listen('tauri://file-drop-hover', (e) => {
  const hoveredElement = document.elementFromPoint(e.x, e.y);

  if (dropzoneElement.contains(hoveredElement)) {
    // ...
  }
});
@probablykasper
Copy link
Member Author

Wry's FileDropEvent does include position: https://docs.rs/wry/latest/wry/webview/enum.FileDropEvent.html

@FabianLars
Copy link
Member

Which means we can use it in tauri v2, or back port it to an older wry version for a possible future 1.X release.

@fanchenio
Copy link

Need mouse coordinates very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants