-
Notifications
You must be signed in to change notification settings - Fork 51
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
WinForms: Unable to focus WebView2 when it's the only focusable control on a form #397
Comments
Thanks so much for pointing this out! Out of curiosity, could you give us some context on what you're building and what scenarios this could potentially be an issue? I've filed a bug for us to investigate further! |
I acknowledge it's probably not a common scenario to have a Such a scenario where the user is dropped into a |
I have a similar use case as @billybooth - using a window/form with only a WebView2 control for authenticating via 3rd party web apps. |
@ShaunLoganOracle, it's working beautifully for us, btw, although the discussion in #374 is making me a bit nervous. |
@billybooth I'm currently trying to reproduce the issue but not exactly sure what your app is doing. I took the WebView2Samples app, stripped out everything besides the webview, and navigated to a simple page with a form and it had focus. Can you describe in a little more detail about how you're trying to set focus? For example, is it through JavaScript or through C#? |
@jamesoli, thanks for getting to this one. I haven't updated my own project in a bit, but I just pulled That said, in Thanks again for your time and consideration on this one! |
One aside noted in this issue report was the loss of input focus when a form containing a Edit: To be clear about all of this, it wouldn't bother me one bit if I were required to focus the C# control after navigation or after parent form activation, there just doesn't appear to be a reliable approach to navigating to an arbitrary page and allowing a default input element to receive input focus. Neither does there seem to be a way on the C# side to activate/focus the control and have input focus restored. |
You're right that currently when the WebView2 control is focused, it doesn't auto focus by default. This is due to how we host the actual content for the WebView. In Win32 world, we have an API called Move Focus that does what you're describing. For WinForms, I think we should have some way for the actual content of the WebView to be able to get focus. My thought is that webView2Control.Focus() should just work and do what you're describing. This would require us to do some underlying work. There are other options like bringing over the MoveFocus API but I'm not hot on that option. |
This should be fixed in the 1.0.781-prerelease package. Thanks! |
As discussed in #185, which appears to be related, when the WebView2 is the only focusable control on a WinForms form, the inner Chromium window cannot receive input focus either programattically via
WebView2.Focus()
or via the keyboard/tab stops.This issue is present in the 0.9.579 prerelease and can easily be replicated by simply removing (or disabling) all of the focusable controls except the
WebView2
from the WebView2Samples WinForms sample.Not a huge deal (can be worked around), but just wanted to let you know. Thanks again for all the work you're doing on this. Very much looking forward to being able to leverage a modern web view!
AB#28588555
The text was updated successfully, but these errors were encountered: