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

Fix WebView2 focus getting stuck #7083

Merged
merged 1 commit into from
May 11, 2022
Merged

Fix WebView2 focus getting stuck #7083

merged 1 commit into from
May 11, 2022

Conversation

krschau
Copy link
Contributor

@krschau krschau commented May 9, 2022

There was an issue where when a WebView2 was the only focusable element and the user tabbed through the content, the focus would get stuck at the end (or beginning) of the WebView2. This change prevents the issue by putting focus back in the webview.

Description

After moving focus all the way through a webview, at the end XAML will receive a MoveFocusRequested message where we would normally put focus on the next XAML element. However, in the case where the webview is the ONLY focusable element, focus did not go back to the webview. Instead, we should check if the next focusable element is the same webview that we're leaving, and if it is, put focus back in the WebView2 with a call to CoreWebView2Controller.MoveFocus(). This results in the focus moving from the end back up to the top, or when moving backwards, from the top back down to the end.

How Has This Been Tested?

This has been tested in a standalone app.

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label May 9, 2022
@krschau krschau requested a review from codendone May 9, 2022 23:57
@krschau
Copy link
Contributor Author

krschau commented May 9, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@krschau krschau added team-Rendering Issue for the Rendering team area-WebView and removed needs-triage Issue needs to be triaged by the area owners labels May 9, 2022
@krschau krschau changed the title Fix WebView2 getting stuck Fix WebView2 focus getting stuck May 10, 2022
// If the next element is this webview, then we are the only focusable element. Move focus back into the webview,
// or else we'll get stuck trying to tab out of the top or bottom of the page instead of looping around.
MoveFocusIntoCoreWebView(moveFocusRequestedReason);
args.Handled(TRUE);
Copy link
Contributor

@codendone codendone May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine. What does CoreWebView2 do if we set args.Handled to FALSE -- does it automatically wrap, such that we maybe don't need to MoveFocusIntoCoreWebView()? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just setting it to FALSE did not automatically wrap.

Copy link
Contributor

@codendone codendone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@krschau krschau merged commit 57224da into main May 11, 2022
@krschau krschau deleted the user/krschau/wv2-loop-focus branch May 11, 2022 19:46
@ghost
Copy link

ghost commented Jun 2, 2022

🎉Microsoft.UI.Xaml v2.8.0-prerelease.220601001 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-WebView team-Rendering Issue for the Rendering team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants