diff --git a/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Android.cs b/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Android.cs index 3dc75e168a60..3501898dcfcf 100644 --- a/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Android.cs +++ b/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Android.cs @@ -20,7 +20,7 @@ void OnWindowDispatchedTouch(object? sender, MotionEvent? e) foreach (var page in _contentPages) { - if (page.HasNavigatedTo && + if ((page.HasNavigatedTo || page.Parent is Window) && page.HideSoftInputOnTapped && page.Handler is IPlatformViewHandler pvh && pvh.MauiContext?.Context is not null) diff --git a/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Platform.cs b/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Platform.cs index b5ed8c838a64..45b49052c65b 100644 --- a/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Platform.cs +++ b/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Platform.cs @@ -14,7 +14,7 @@ partial class HideSoftInputOnTappedChangedManager internal void UpdatePage(ContentPage page) { - if (page.HideSoftInputOnTapped && page.HasNavigatedTo) + if (page.HideSoftInputOnTapped && (page.HasNavigatedTo || page.Parent is Window)) { if (!_contentPages.Contains(page)) { diff --git a/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.cs b/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.cs index 1f369165f5f8..17f1c41e75d7 100644 --- a/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.cs +++ b/src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.cs @@ -13,7 +13,7 @@ bool FeatureEnabled { foreach (var page in _contentPages) { - if (page.HideSoftInputOnTapped && page.HasNavigatedTo) + if (page.HideSoftInputOnTapped && (page.HasNavigatedTo || page.Parent is Window)) return true; } return false; diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue26792.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue26792.cs new file mode 100644 index 000000000000..cb4045de9468 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue26792.cs @@ -0,0 +1,40 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 26792, "HideSoftInputOnTapped Not Working", PlatformAffected.Android)] +public class Issue26792 : ContentPage +{ + + VerticalStackLayout stackLayout; + Button _button; + + Entry _entry; + public Issue26792() + { + this.HideSoftInputOnTapped = true; + stackLayout = new VerticalStackLayout + { + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + AutomationId = "Issue26792StackLayout", + }; + _button = new Button + { + Text = "Click Me", + AutomationId = "Issue26792Button", + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + }; + _entry = new Entry + { + Placeholder = "Enter text", + AutomationId = "Issue26792Entry", + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + }; + + stackLayout.Children.Add(_button); + stackLayout.Children.Add(_entry); + Content = stackLayout; + } +} + diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26792.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26792.cs new file mode 100644 index 000000000000..88bd8968731c --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26792.cs @@ -0,0 +1,29 @@ +#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS //As SoftKeyboard is not supported +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue26792 : _IssuesUITest +{ + public Issue26792(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "HideSoftInputOnTapped Not Working"; + + [Test] + [Category(UITestCategories.Page)] + public void SoftInputShouldHiddenOnTap() + { + App.WaitForElement("Issue26792Entry"); + App.Tap("Issue26792Entry"); + App.WaitForElement("Issue26792Button"); + App.Tap("Issue26792Button"); + App.WaitForElement("Issue26792Entry"); + Assert.That(App.IsKeyboardShown(), Is.False); + + } +} +#endif