Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shift+tab traps focus inside WinForms WebView2 control when wrapped in a ContainerControl #2835

Closed
MackinnonBuck opened this issue Sep 29, 2022 · 4 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@MackinnonBuck
Copy link

MackinnonBuck commented Sep 29, 2022

Description
When a WinForms WebView2 control is a child element of a ContainerControl, shift+tab navigation cannot move focus out of the WebView. While focus cannot escape the WebView in the reverse direction, it can escape the WebView in the forward direction.

This bug affects the BlazorWebView WinForms control, which extends ContainerControl and wraps the WebView2 control.

Version
SDK: 1.0.1369-prerelease
Runtime: Stable 105.0.1343.53
Framework: WinForms
OS: Windows 11 Enterprise Version 22H2

Repro Steps

  1. Create a new Windows Forms App (.NET 7) and add a reference to Microsoft.Web.WebView2.
  2. Replace the code in the Form1 constructor with the following:
InitializeComponent();

var button1 = new Button { Text = "button1", TabIndex = 0 };
var webViewContainer = new ContainerControl { Width = 220, Height = 40, Top = 30, TabIndex = 1 };
var webView = new Microsoft.Web.WebView2.WinForms.WebView2 { Dock = DockStyle.Fill };

webViewContainer.Controls.Add(webView);

Controls.Add(button1);
Controls.Add(webViewContainer);

_ = InitializeWebViewAsync();

async Task InitializeWebViewAsync()
{
    await webView.EnsureCoreWebView2Async();
    webView.NavigateToString("""
        <!DOCTYPE html>
        <head>
        </head>
        <body>
            <button type="button">button2</button>
            <button type="button">button3</button>
            <button type="button">button4</button>
        </body>
        """);
}
  1. Run the application.
  2. Repeatedly press tab, observing that the focus correctly enters and exits the WebView.
  3. Repeatedly press shift+tab, observing that focus gets trapped inside the WebView.

Expected behavior: When the first HTML element in the WebView has focus and shift+tab is pressed, the Windows Forms control previous to the WebView2 control should receive focus.

Actual behavior: When the first HTML element in the WebView has focus, shift+tabbing results in the last element in the WebView receiving focus.

Screen recording

winforms_tab_navigation.mp4

Additional context

dotnet/maui#8293

AB#43460910

@victorthoang
Copy link

hello @MackinnonBuck,

I've assigned your query to one of our devs to investigate the bug. Thanks and we shall get back to you.

@oggy22 oggy22 assigned novac42 and unassigned oggy22 Feb 9, 2023
@ElyssaJyu ElyssaJyu added the tracked We are tracking this work internally. label Feb 22, 2023
@ElyssaJyu
Copy link

Hi @MackinnonBuck, thanks for your report, it seems a bug exists, I will track it internally.
If this blocks your work, as a current alternative, you can use Controls.Add(webView), instead of using ContrainerControl to wrapper webview2

@ShaunLoganOracle
Copy link

This issue is shown as fixed in the release notes for 1.0.1777-prerelease. I was hopeful that the same fix might have helped with #951 , but that issue still reproduces.

@champnic
Copy link
Member

champnic commented Apr 24, 2023

As noted, this is fixed in SDKs 1.0.1777-prerelease+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

7 participants