From f46ef07c53263f7a3c23feb4faebe423703f3e37 Mon Sep 17 00:00:00 2001 From: "SmileSky (mzdk100)" Date: Tue, 14 Jan 2025 16:50:30 +0800 Subject: [PATCH] fix: Fix the issue where TAB cannot cycle through focus elements. Signed-off-by: SmileSky --- .changes/element-focus.md | 5 +++++ src/webview2/mod.rs | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 .changes/element-focus.md diff --git a/.changes/element-focus.md b/.changes/element-focus.md new file mode 100644 index 000000000..ec8200fab --- /dev/null +++ b/.changes/element-focus.md @@ -0,0 +1,5 @@ +--- +'wry': 'patch:enhance' +--- + +Allow the use of TAB to cycle through focus elements in an HTML document. \ No newline at end of file diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index ca4bb96c7..1767497db 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -176,6 +176,16 @@ impl InnerWebView { wparam: WPARAM, lparam: LPARAM, ) -> LRESULT { + if msg == WM_SETFOCUS { + // Fix https://github.com/DioxusLabs/dioxus/issues/2900 + // Get the first child window of the window + let child = GetWindow(hwnd, GW_CHILD).unwrap_or_default(); + if child != HWND::default() { + // Set focus to the child window(WebView document) + let _ = SetFocus(child); + } + } + DefWindowProcW(hwnd, msg, wparam, lparam) }