Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
593a6e1
new events
May 27, 2025
504f05d
macOS dnd improvements
May 27, 2025
86565d6
wailsio adds for dropzone
May 27, 2025
66ed1c3
update example
May 27, 2025
472f8cb
sorta working
May 27, 2025
5084a84
implement attribute detection for data-wails-dropzone
May 29, 2025
bcf244d
docs
May 29, 2025
03890af
pass x/y dnd linux
May 29, 2025
357894b
cleanup exmample
May 29, 2025
c92b13e
changelog
May 29, 2025
5f8ff66
pass all attributes to golang on dragdrop
May 29, 2025
1c7e9ad
filetree example
May 29, 2025
abd5d09
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony May 30, 2025
e040e07
fix dnd build windows
Jun 2, 2025
8c7de99
Fix windows dnd
Jun 4, 2025
8c557fe
update docs
atterpac Jun 4, 2025
4f1ff27
Merge remote-tracking branch 'wails/v3-alpha' into v3/dnd-zones
atterpac Jul 12, 2025
0646459
remove debug log
atterpac Jul 12, 2025
f305c9e
appease the security bot
atterpac Jul 13, 2025
afe585a
Merge branch 'v3-alpha' into v3/dnd-zones
atterpac Jul 13, 2025
55aef8d
Fix changelog
leaanthony Jul 15, 2025
c6dde6e
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Jul 15, 2025
c9c2de2
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Jul 19, 2025
115935d
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Jul 21, 2025
e0285c6
Fix changelog
leaanthony Jul 24, 2025
04dd966
Merge branch 'v3-alpha' into fork/atterpac/v3/dnd-zones
leaanthony Jul 24, 2025
eca9f58
Revert "Fix event generation issues."
leaanthony Jul 24, 2025
96ab50f
Fix events
leaanthony Jul 24, 2025
86c2a21
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Jul 24, 2025
cad22ad
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Jul 24, 2025
f853e4f
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Jul 24, 2025
9267b0c
Merge branch 'v3-alpha' into fork/atterpac/v3/dnd-zones
leaanthony Jul 24, 2025
9693afd
Fix merge conflicts. Fix events generation formatting
leaanthony Jul 24, 2025
a312674
Update docs
leaanthony Jul 24, 2025
042af21
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Jul 24, 2025
85ac4c8
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Jul 30, 2025
d70f6fe
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Jul 30, 2025
99ec1cd
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Aug 2, 2025
5e0be94
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Aug 2, 2025
3ea5a29
Fix duplicate bundledassets import causing build failures
leaanthony Aug 2, 2025
d77b37b
Replace fmt.Printf debug statements with globalApplication.debug
leaanthony Aug 2, 2025
cb9dcd2
Add nil checks to WindowEventContext methods
leaanthony Aug 2, 2025
7bc850b
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Aug 3, 2025
f96bd2e
Update v3/pkg/application/webview_window_darwin.m
leaanthony Aug 3, 2025
b38c71a
reinstate events docs.
leaanthony Aug 4, 2025
d9b4b12
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Aug 4, 2025
074932f
Merge branch 'v3-alpha' into v3/dnd-zones
leaanthony Aug 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/content/docs/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Support for dropzones with event sourcing dropped element data [@atterpac](https://github.com/atterpac) in [#4318](https://github.com/wailsapp/wails/pull/4318)
- Support aarch64 AppImage builds by [@AkshayKalose](https://github.com/AkshayKalose) in [#3981](https://github.com/wailsapp/wails/pull/3981)
- Add diagnostics section to `wails doctor` by [@leaanthony](https://github.com/leaanthony)
- Add window to context when calling a service method by [@leaanthony](https://github.com/leaanthony)
Expand Down
131 changes: 131 additions & 0 deletions docs/src/content/docs/learn/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,137 @@ INF I always run after hooks!
| WindowZoomOut | Window zoomed out |
| WindowZoomReset | Window zoom reset |

### Enhanced Drag and Drop with Targeted Dropzones

Wails v3 introduces an enhanced drag-and-drop system that allows you to define specific "dropzones" within your application's HTML. This provides finer control over where files can be dropped and offers automatic visual feedback managed by the Wails runtime.

#### 1. Defining Dropzones in HTML

To designate an HTML element as a dropzone, add the `data-wails-dropzone` attribute to it. Any element with this attribute will become a valid target for file drops.

**Example:**
```html
<div id="myDropArea" class="my-styles" data-wails-dropzone>
<p>Drop files here!</p>
</div>

<div id="anotherZone" data-wails-dropzone style="width: 300px; height: 100px; border: 1px solid grey;">
Another drop target
</div>

<!-- Advanced example with custom data attributes -->
<div class="tree-node folder folder-dropzone"
data-wails-dropzone
data-folder-id="documents"
data-folder-name="Documents"
data-path="/home/user/Documents">
<span>📁 Documents</span>
</div>
```
Comment thread
leaanthony marked this conversation as resolved.

#### 2. Visual Feedback

When files are dragged over an element marked with `data-wails-dropzone`, the Wails JavaScript runtime automatically adds the `wails-dropzone-hover` CSS class to that element. You can define styles for this class to provide visual feedback:

**Example CSS:**
```css
/* Base style for all dropzones (resting state) */
.dropzone {
border: 2px dashed #888;
background-color: #303030;
padding: 20px;
text-align: center;
}

/* Default hover effect applied by the runtime */
.dropzone.wails-dropzone-hover {
background-color: #3c3c3e;
border-style: dotted;
border-color: #007bff;
box-shadow: 0 0 8px rgba(0, 123, 255, 0.4);
}

/* Example: Customizing hover for a specific dropzone to override the default */
#myDropArea.wails-dropzone-hover {
background-color: lightgreen;
outline: 2px solid green;
}
```
The runtime handles adding and removing the `wails-dropzone-hover` class as files are dragged in and out of the dropzone or the window.

#### 3. Handling Drops in Go

On the Go side, listen for the `events.Common.WindowDropZoneFilesDropped` event. This event will be emitted when files are dropped onto an element that has the `data-wails-dropzone` attribute.

**Example Go Handler:**
```go
import (
"fmt"
"log"
"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/events"
)

// Assuming 'win' is your *application.WebviewWindow instance
win.OnWindowEvent(events.Common.WindowDropZoneFilesDropped, func(event *application.WindowEvent) {
droppedFiles := event.Context().DroppedFiles()
log.Printf("Files dropped: %v", droppedFiles)

details := event.Context().DropZoneDetails()
if details != nil {
log.Printf("Dropped on Element ID: '%s'", details.ElementID)
log.Printf("Element Classes: %v", details.ClassList)
log.Printf("Drop Coordinates (relative to window): X=%d, Y=%d", details.X, details.Y)

// Access custom data attributes from the HTML element
if folderName, exists := details.Attributes["data-folder-name"]; exists {
log.Printf("Folder name: %s", folderName)
}
if folderPath, exists := details.Attributes["data-path"]; exists {
log.Printf("Target path: %s", folderPath)
}

// Example: Handle different dropzone types based on ElementID
switch details.ElementID {
case "documents":
log.Printf("Files dropped on Documents folder")
// Handle document uploads
case "downloads":
log.Printf("Files dropped on Downloads folder")
// Handle download folder drops
case "trash":
Comment on lines +294 to +301

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Correct element ID usage in Go handler

The Go example switches on details.ElementID, but the advanced HTML example only sets data-folder-id. You can either give the element an id (as suggested) or change the switch to use the attribute:

-    switch details.ElementID {
+    folderID := details.Attributes["data-folder-id"]
+    switch folderID {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
switch details.ElementID {
case "documents":
log.Printf("Files dropped on Documents folder")
// Handle document uploads
case "downloads":
log.Printf("Files dropped on Downloads folder")
// Handle download folder drops
case "trash":
folderID := details.Attributes["data-folder-id"]
switch folderID {
case "documents":
log.Printf("Files dropped on Documents folder")
// Handle document uploads
case "downloads":
log.Printf("Files dropped on Downloads folder")
// Handle download folder drops
case "trash":
🤖 Prompt for AI Agents
In docs/src/content/docs/learn/events.mdx around lines 294 to 301, the Go code
switches on details.ElementID, but the HTML example uses data-folder-id
attribute instead of an id. To fix this, either update the HTML elements to
include an id attribute matching the expected values ("documents", "downloads",
"trash") or modify the Go switch statement to read the data-folder-id attribute
value instead of ElementID for correct matching.

log.Printf("Files dropped on Trash")
// Handle file deletion
default:
log.Printf("Files dropped on unknown target: %s", details.ElementID)
}

payload := map[string]interface{}{
"files": droppedFiles,
"targetID": details.ElementID,
"targetClasses": details.ClassList,
"dropX": details.X,
"dropY": details.Y,
"attributes": details.Attributes,
}
application.Get().EmitEvent("frontend:FileDropInfo", payload) // Emits globally
// or win.EmitEvent("frontend:FileDropInfoForWindow", payload) // Emits to this specific window
} else {
log.Println("Drop occurred, but DropZoneDetails were nil.")
}
})
```
The `event.Context().DropZoneDetails()` method returns a pointer to an `application.DropZoneDetails` struct (or `nil` if details aren't available), containing:
- `ElementID string`: The id of the element dropped onto
- `ClassList []string`: The list of CSS classes of the HTML element that received the drop.
- `X int`: The X-coordinate of the drop, relative to the window's content area.
- `Y int`: The Y-coordinate of the drop, relative to the window's content area.
- `Attributes map[string]string`: A map containing all HTML attributes of the target element, allowing access to custom data attributes like `data-path`, `data-folder-name`, etc.

The `event.Context().DroppedFiles()` method returns a `[]string` of file paths.

For a fully runnable demonstration of these features, including multiple styled dropzones, please refer to the example located in the `v3/examples/drag-n-drop` directory within the Wails repository.

### Platform-Specific Window Events

<Tabs>
Expand Down
Loading