fix(v3): implement file picker for input type=file on macOS (#4862)

Add WKUIDelegate protocol support to handle runOpenPanelWithParameters
delegate method, which is required for <input type="file"> elements to
work in WKWebView on macOS. This was a regression from V2 which had
this implementation.

Changes:
- Add WKUIDelegate to WebviewWindowDelegate protocol list
- Set UIDelegate on WKWebView during window creation
- Implement runOpenPanelWithParameters to show NSOpenPanel for file selection

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Lea Anthony 2026-02-03 06:59:34 +11:00
commit cef60037fd
4 changed files with 20 additions and 1 deletions

View file

@ -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 `<input type="file">` file picker not working on macOS (#4862) by @leaanthony
## Deprecated
<!-- Soon-to-be removed features -->

View file

@ -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];

View file

@ -18,7 +18,7 @@
@end
@interface WebviewWindowDelegate : NSObject <NSWindowDelegate, WKScriptMessageHandler, WKNavigationDelegate, WKURLSchemeHandler, NSDraggingDestination>
@interface WebviewWindowDelegate : NSObject <NSWindowDelegate, WKScriptMessageHandler, WKNavigationDelegate, WKURLSchemeHandler, NSDraggingDestination, WKUIDelegate>
@property unsigned int windowId;
@property (retain) NSEvent* leftMouseEvent;

View file

@ -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<NSURL *> * 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;