-
Notifications
You must be signed in to change notification settings - Fork 2k
[Windows] Fix modal page keyboard focus not shifting to newly opened modal #34212
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ea0b1d4
Fix modal page keyboard focus on Windows
jfversluis 11fadb2
Address PR review: improve focus handling and test robustness
jfversluis 3c1f931
Fix potential memory leak and duplicate Loaded subscriptions
jfversluis f0d5519
Enhance focus trapping: TabFocusNavigation + transparent modal support
jfversluis ef36bb5
Use GettingFocus event trap instead of IsEnabled/TabFocusNavigation
jfversluis 7a3f1db
Fix post-pop focus restoration and delegate storage
jfversluis ca178fe
Fix stale focus trap during modal removal + add device test
jfversluis 5640b97
Fix semi-transparent modal focus trap and post-pop interaction
jfversluis 0f5a9bf
Address review: restore TabFocusNavigation on pop, add nested modals …
jfversluis 20faf34
Cache and restore original IsHitTestVisible on modal pop
jfversluis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 22938, "Keyboard focus does not shift to a newly opened modal page", PlatformAffected.All)] | ||
|
jfversluis marked this conversation as resolved.
|
||
| public class Issue22938 : ContentPage | ||
| { | ||
| public Issue22938() | ||
| { | ||
| var clickCountLabel = new Label | ||
| { | ||
| Text = "0", | ||
| AutomationId = "ClickCountLabel", | ||
| FontSize = 24 | ||
| }; | ||
|
|
||
| var mainPageButton = new Button | ||
| { | ||
| Text = "Click Me", | ||
| AutomationId = "MainPageButton", | ||
| Command = new Command(() => | ||
| { | ||
| int count = int.Parse(clickCountLabel.Text); | ||
| clickCountLabel.Text = (count + 1).ToString(); | ||
| }) | ||
| }; | ||
|
|
||
| var openModalButton = new Button | ||
| { | ||
| Text = "Open Modal", | ||
| AutomationId = "OpenModalButton", | ||
| Command = new Command(async () => | ||
| { | ||
| var modalPage = new ContentPage | ||
| { | ||
| BackgroundColor = Colors.Beige, | ||
| Content = new VerticalStackLayout | ||
| { | ||
| Spacing = 20, | ||
| Padding = new Thickness(30), | ||
| VerticalOptions = LayoutOptions.Center, | ||
| Children = | ||
| { | ||
| new Label | ||
| { | ||
| Text = "Modal Page", | ||
| AutomationId = "ModalPageLabel", | ||
| FontSize = 24, | ||
| HorizontalOptions = LayoutOptions.Center | ||
| }, | ||
| new Button | ||
| { | ||
| Text = "Close Modal", | ||
| AutomationId = "CloseModalButton", | ||
| Command = new Command(async () => | ||
| { | ||
| await Navigation.PopModalAsync(); | ||
| }) | ||
| }, | ||
| new Entry | ||
| { | ||
| Placeholder = "Focus target on modal", | ||
| AutomationId = "ModalEntry" | ||
| } | ||
| } | ||
|
jfversluis marked this conversation as resolved.
|
||
| } | ||
| }; | ||
|
|
||
| await Navigation.PushModalAsync(modalPage); | ||
| }) | ||
| }; | ||
|
|
||
| Content = new VerticalStackLayout | ||
| { | ||
| Spacing = 20, | ||
| Padding = new Thickness(30), | ||
| VerticalOptions = LayoutOptions.Center, | ||
| Children = | ||
| { | ||
| new Label | ||
| { | ||
| Text = "Main Page - Issue 22938", | ||
| FontSize = 24 | ||
| }, | ||
| mainPageButton, | ||
| clickCountLabel, | ||
| openModalButton | ||
| } | ||
| }; | ||
| } | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22938.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue22938 : _IssuesUITest | ||
| { | ||
| public Issue22938(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "Keyboard focus does not shift to a newly opened modal page"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Focus)] | ||
| public void ModalPageShouldReceiveKeyboardFocus() | ||
| { | ||
| App.WaitForElement("OpenModalButton"); | ||
|
|
||
| // Open the modal page | ||
| App.Tap("OpenModalButton"); | ||
|
|
||
| // Wait for modal to appear | ||
| App.WaitForElement("ModalPageLabel"); | ||
|
|
||
| // Press Enter — if focus is correctly on the modal, this should NOT | ||
| // activate the MainPage button (click count should stay at 0) | ||
| App.PressEnter(); | ||
|
|
||
| // Close the modal | ||
| App.Tap("CloseModalButton"); | ||
|
|
||
|
jfversluis marked this conversation as resolved.
|
||
| // Wait for main page to reappear | ||
| App.WaitForElement("ClickCountLabel"); | ||
|
|
||
| // Verify the main page button was NOT clicked by the Enter key | ||
| var clickCount = App.WaitForElement("ClickCountLabel").GetText(); | ||
| Assert.That(clickCount, Is.EqualTo("0"), | ||
| "Enter key should not activate buttons on the page beneath a modal"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.