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 564ca2e11..dcc338ae3 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).ok(); + if child.is_some() { + // Set focus to the child window(WebView document) + let _ = SetFocus(child); + } + } + DefWindowProcW(hwnd, msg, wparam, lparam) } @@ -1671,14 +1681,19 @@ unsafe fn set_background_color( controller: &ICoreWebView2Controller, background_color: RGBA, ) -> Result<()> { - let (R, G, B, mut A) = background_color; - if is_windows_7() || A != 0 { - A = 255; + let (r, g, b, mut a) = background_color; + if is_windows_7() || a != 0 { + a = 255; } let controller2: ICoreWebView2Controller2 = controller.cast()?; controller2 - .SetDefaultBackgroundColor(COREWEBVIEW2_COLOR { R, G, B, A }) + .SetDefaultBackgroundColor(COREWEBVIEW2_COLOR { + R: r, + G: g, + B: b, + A: a, + }) .map_err(Into::into) }