#The drag and drop is not working

6 messages ยท Page 1 of 1 (latest)

near yew
#

I have made a frameless app 256x256 with a movable window feature... It's an mp3 player.. What I want is that I should be able to select files from my pc and drop it inside the small window. And that song shows up.. Or at least its name shows up.... But when I bring the file over... I do see my cursor change... But the file doesn't get uploaded

My code works fine when opened in web view... But on my windows 11..it doesn't work... I even tried the "dragDropEnabled: false" thing.. Still didn't work...

I am using tauri v2 btw

green temple
#

@near yew Its hard to say whats really happening without any code examples. But this should work. Are you trying to do this all via Javascript or Rust? In Javascript you can call

WebviewWindow.getCurrent().onDragDropEvent(() => {});

#

If you're using React-TS, heres a simple hook that should work no problem:

import { Event } from '@tauri-apps/api/event';
import { DragDropEvent, WebviewWindow } from '@tauri-apps/api/webviewWindow';

const useFileDrop = () => {

    const handleDrop = React.useCallback((event: Event<DragDropEvent>) => {
        if (event.payload.type === 'drop' && event.payload.paths.length > 0) {
            // Handle the file drop event
        }
    }, []);

    React.useEffect(() => {
        const window = WebviewWindow.getCurrent();
        const unlisten = window.onDragDropEvent(handleDrop);

        return () => {
            unlisten.then((f) => f());
        };
    }, [handleDrop]);
};
near yew
#

oh it worked ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰

#

Thank you so much