5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 03:52:41 +08:00
wails/website/docs/reference/runtime/draganddrop.mdx
Jakub Peleška 022a5ffec4
Fix Drag & Drop JS runtime (#3516)
* Feature/1090 native drag and drop for file and folder (#3203)

* implement basic dnd for linux

* implemented windows

* progress changed linux handling and added coordinates to drop

* progress fix drop coordinates on windows

* progress remove log from windows

* progress move js

* update js after merge

* fix event listener registration

* fix segfault on non file drag

* remove logs, fix coordinates

* minor changes, simplify to drop only

* rename EnableWails -> EnableFileDrop

* add documentation (PR id missing)

* add PR id to changelog

* fix remove casting from malloc

* fix nil check for OnFileDrop's callback

* fix nil check for OnFileDrop skip event when nil

* add error message for nil callback in OnFileDrop

---------

Co-authored-by: lyimmi <lelvente.zambo@gmail.com>
Co-authored-by: Lea Anthony <lea.anthony@gmail.com>

* implement native drag and drop for macOS (#3250)

* implement native drag and drop for macOS

* update docs

* add to changelog

* update docs (macOS is supported)

* Fix windows DragAndDrop options

* Fix class unset on dragleave for full frame elements

* improve class unset (nested elements and borders case)

* Fix runtime drop target detection and CSS class assignment

* Edit changelog

* Fix drag-and-drop options in references

* Update v2/internal/frontend/desktop/darwin/WailsWebView.m

* Update v2/internal/frontend/desktop/darwin/WailsWebView.m

---------

Co-authored-by: Zámbó, Levente <levente.zambo@gmail.com>
Co-authored-by: lyimmi <lelvente.zambo@gmail.com>
Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
Co-authored-by: Andrey Pshenkin <andrey.pshenkin@gmail.com>
Co-authored-by: Pavel Binar <pavel@beamtransfer.io>
2024-06-10 15:15:28 +10:00

39 lines
1.5 KiB
Plaintext

---
sidebar_position: 10
---
# Drag And Drop
:::
This part of the runtime handles dragging and dropping files and or folders in to the window.<br/>
To enable this functionality you have to set [EnableFileDrop](../../reference/options.mdx#enablefiledrop) to `true`
in [Application Options](../../reference/options.mdx#drag-and-drop).
### OnFileDrop
This method handles the drop event on the window.
Go: `OnFileDrop(ctx context.Context, callback func(x, y int, paths []string))`<br/>
Calls the callback function with the coordinates inside the window where the drag was released and a slice of absolute file paths.
JS: `OnFileDrop(callback: (x: number, y: number, paths: string[]) => void, useDropTarget: boolean) :void`<br/>
Calls the callback function with the coordinates inside the window where the drag was released and a slice of absolute file paths.
When the `useDropTarget` is `true` in addition to calling the callback when the drop happens, it registers event listeners on
the window that are listening for the drag coordinates and checks if the mouse is over an element that has the
[CSSDropProperty](../../reference/options.mdx#cssdropproperty) style. If the element has the required property
it adds the `wails-drop-target-active` class to the element's class list and removes it when the mouse moves off of it.
### OnFileDropOff
This method removes all registered listeners and handlers for drag and drop events.
Go: `OnFileDropOff(ctx context.Context)`<br/>
Returns: has no return value.
JS: `OnFileDropOff(): void`<br/>
Returns: has no return value.