-
Notifications
You must be signed in to change notification settings - Fork 2k
[Windows] Fix SearchHandler does not focus when ShowSoftInputAsync is called #35079
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
kubaflo
merged 8 commits into
dotnet:inflight/current
from
praveenkumarkarunanithi:fix-22151
May 21, 2026
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1e598e0
fix and test code update
praveenkumarkarunanithi 3b14a7c
Update ShellItemHandler.Windows.cs
praveenkumarkarunanithi 7175e0f
updated windows fix and test as per new API
praveenkumarkarunanithi 2ed2061
updated test
praveenkumarkarunanithi bed6295
Update Issue22151.cs
praveenkumarkarunanithi 4463c98
test name updated
praveenkumarkarunanithi e15c3ff
Merge remote-tracking branch 'upstream/main' into fix-22151
praveenkumarkarunanithi 386426c
updated test as per ai concerns.
praveenkumarkarunanithi 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
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
103 changes: 103 additions & 0 deletions
103
src/Controls/tests/TestCases.HostApp/Issues/Issue34930.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,103 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 34930, "SearchHandler.ShowSoftInputAsync() does not focus the SearchHandler", PlatformAffected.UWP)] | ||
| public class Issue34930 : Shell | ||
| { | ||
| public Issue34930() | ||
| { | ||
| var flyoutItem = new FlyoutItem | ||
| { | ||
| Route = "home", | ||
| FlyoutDisplayOptions = FlyoutDisplayOptions.AsSingleItem | ||
| }; | ||
|
|
||
| flyoutItem.Items.Add(new Tab | ||
| { | ||
| Title = "Home", | ||
| Route = "hometab", | ||
| Items = | ||
| { | ||
| new ShellContent | ||
| { | ||
| Title = "Home", | ||
| Route = "homepage", | ||
| ContentTemplate = new DataTemplate(typeof(_34930TestPage)) | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| Items.Add(flyoutItem); | ||
| } | ||
|
|
||
| public class _34930TestPage : ContentPage | ||
| { | ||
| public _34930TestPage() | ||
| { | ||
| Title = "Home"; | ||
|
|
||
| var isFocusedLabel = new Label | ||
| { | ||
| Text = "IsFocused: False", | ||
| AutomationId = "isFocusedLabel" | ||
| }; | ||
|
|
||
| var focusedEventLabel = new Label | ||
| { | ||
| Text = "FocusedEvent: False", | ||
| AutomationId = "focusedEventLabel" | ||
| }; | ||
|
|
||
| var searchHandler = new SearchHandler | ||
| { | ||
| AutomationId = "searchHandler", | ||
|
praveenkumarkarunanithi marked this conversation as resolved.
Outdated
praveenkumarkarunanithi marked this conversation as resolved.
Outdated
|
||
| Placeholder = "Search...", | ||
| SearchBoxVisibility = SearchBoxVisibility.Expanded, | ||
| ShowsResults = false | ||
| }; | ||
|
|
||
| searchHandler.Focused += (s, e) => | ||
| { | ||
| focusedEventLabel.Text = "FocusedEvent: True"; | ||
| }; | ||
|
|
||
| var showKeyboardButton = new Button | ||
| { | ||
| Text = "Show Soft Input", | ||
| AutomationId = "ShowKeyboardButton" | ||
| }; | ||
|
|
||
| showKeyboardButton.Clicked += async (s, e) => | ||
| { | ||
| searchHandler.ShowSoftInputAsync(); | ||
| await Task.Delay(200); | ||
| isFocusedLabel.Text = $"IsFocused: {searchHandler.IsFocused}"; | ||
|
praveenkumarkarunanithi marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| var hideKeyboardButton = new Button | ||
| { | ||
| Text = "Hide Soft Input", | ||
| AutomationId = "HideKeyboardButton" | ||
| }; | ||
|
|
||
| hideKeyboardButton.Clicked += (s, e) => | ||
| { | ||
| searchHandler.HideSoftInputAsync(); | ||
| }; | ||
|
|
||
| Shell.SetSearchHandler(this, searchHandler); | ||
|
|
||
| Content = new VerticalStackLayout | ||
| { | ||
| Spacing = 15, | ||
| Padding = 20, | ||
| Children = | ||
| { | ||
| showKeyboardButton, | ||
| hideKeyboardButton, | ||
| isFocusedLabel, | ||
| focusedEventLabel | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34930.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,29 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues | ||
| { | ||
| public class Issue34930 : _IssuesUITest | ||
| { | ||
| public override string Issue => "SearchHandler.ShowSoftInputAsync() does not focus the SearchHandler on Windows"; | ||
|
|
||
| public Issue34930(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.SearchBar)] | ||
|
praveenkumarkarunanithi marked this conversation as resolved.
Outdated
|
||
| public void SearchHandlerShowSoftInputShouldFocusSearchHandlerOnWindows() | ||
| { | ||
| App.WaitForElement("ShowKeyboardButton"); | ||
| App.Tap("ShowKeyboardButton"); | ||
|
|
||
|
praveenkumarkarunanithi marked this conversation as resolved.
|
||
| var isFocused = App.WaitForElement("isFocusedLabel").GetText(); | ||
| Assert.That(isFocused, Is.EqualTo("IsFocused: True")); | ||
|
|
||
|
praveenkumarkarunanithi marked this conversation as resolved.
|
||
| var focusedEvent = App.WaitForElement("focusedEventLabel").GetText(); | ||
| Assert.That(focusedEvent, Is.EqualTo("FocusedEvent: True")); | ||
|
praveenkumarkarunanithi marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| } | ||
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.