diff --git a/v3/UNRELEASED_CHANGELOG.md b/v3/UNRELEASED_CHANGELOG.md
index c9e35a240..5326ed8f2 100644
--- a/v3/UNRELEASED_CHANGELOG.md
+++ b/v3/UNRELEASED_CHANGELOG.md
@@ -32,6 +32,7 @@ After processing, the content will be moved to the main changelog and this file
- Make menus to be displayed on Windows OS in `v3\examples\dialogs` by @ndianabasi
- Fix race condition causing TypeError during page reload (#4872) by @ddmoney420
- Fix incorrect output from binding generator tests by removing global state in the `Collector.IsVoidAlias()` method (#4941) by @fbbdev
+- Fix `` file picker not working on macOS (#4862) by @leaanthony
## Deprecated
diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go
index d4534b501..4a53d7337 100644
--- a/v3/pkg/application/webview_window_darwin.go
+++ b/v3/pkg/application/webview_window_darwin.go
@@ -111,6 +111,7 @@ void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWa
// support webview events
[webView setNavigationDelegate:delegate];
+ [webView setUIDelegate:delegate];
// Ensure webview resizes with the window
[webView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
diff --git a/v3/pkg/application/webview_window_darwin.h b/v3/pkg/application/webview_window_darwin.h
index 11fe1ab3a..489ff582e 100644
--- a/v3/pkg/application/webview_window_darwin.h
+++ b/v3/pkg/application/webview_window_darwin.h
@@ -18,7 +18,7 @@
@end
-@interface WebviewWindowDelegate : NSObject
+@interface WebviewWindowDelegate : NSObject
@property unsigned int windowId;
@property (retain) NSEvent* leftMouseEvent;
diff --git a/v3/pkg/application/webview_window_darwin.m b/v3/pkg/application/webview_window_darwin.m
index 7b47ffbbd..b508820c7 100644
--- a/v3/pkg/application/webview_window_darwin.m
+++ b/v3/pkg/application/webview_window_darwin.m
@@ -780,6 +780,23 @@ typedef NS_ENUM(NSInteger, MacLiquidGlassStyle) {
}
}
// GENERATED EVENTS END
+
+// WKUIDelegate - Handle file input element clicks
+- (void)webView:(WKWebView *)webView runOpenPanelWithParameters:(WKOpenPanelParameters *)parameters
+ initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSArray * URLs))completionHandler {
+ NSOpenPanel *openPanel = [NSOpenPanel openPanel];
+ openPanel.allowsMultipleSelection = parameters.allowsMultipleSelection;
+ if (@available(macOS 10.14, *)) {
+ openPanel.canChooseDirectories = parameters.allowsDirectories;
+ }
+ [openPanel beginSheetModalForWindow:webView.window
+ completionHandler:^(NSInteger result) {
+ if (result == NSModalResponseOK)
+ completionHandler(openPanel.URLs);
+ else
+ completionHandler(nil);
+ }];
+}
@end
void windowSetScreen(void* window, void* screen, int yOffset) {
WebviewWindow* nsWindow = (WebviewWindow*)window;