Skip to content

[Android & iOS] - Fixed Entry and Editor from Accepting Input Values While Hidden. #27340

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Controls/src/Core/Editor/Editor.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class Editor

#if IOS || ANDROID
EditorHandler.Mapper.AppendToMapping(nameof(VisualElement.IsFocused), InputView.MapIsFocused);
EditorHandler.Mapper.AppendToMapping(nameof(VisualElement.IsVisible), InputView.MapIsVisible);
#endif

#if ANDROID
Expand Down
1 change: 1 addition & 0 deletions src/Controls/src/Core/Entry/Entry.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class Entry

#if IOS || ANDROID
EntryHandler.Mapper.AppendToMapping(nameof(VisualElement.IsFocused), InputView.MapIsFocused);
EntryHandler.Mapper.AppendToMapping(nameof(VisualElement.IsVisible), InputView.MapIsVisible);
#endif

#if ANDROID
Expand Down
12 changes: 12 additions & 0 deletions src/Controls/src/Core/InputView/InputView.Platform.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;

namespace Microsoft.Maui.Controls
{
Expand All @@ -14,6 +15,17 @@ internal static void MapIsFocused(IViewHandler handler, IView view)
?.UpdateFocusForView(iv);
}
}

internal static void MapIsVisible(IViewHandler handler, IView view)
{
if (view is not InputView inputView || handler?.PlatformView is null)
return;

if (!inputView.IsVisible && inputView.IsSoftInputShowing())
{
inputView.HideSoftInputAsync(CancellationToken.None);
}
}
#endif
}
}
53 changes: 53 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27236.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 27236, "android allows type into hidden Entry control", PlatformAffected.Android | PlatformAffected.iOS)]
public partial class Issue27236 : TestContentPage
{
protected override void Init()
{
StackLayout mainLayout = new StackLayout
{
Padding = new Thickness(10)
};

Entry toggleableEntry = new Entry
{
AutomationId = "ToggleableEntry",
IsVisible = false
};

Editor toggleableEditor = new Editor
{
AutomationId = "ToggleableEditor",
IsVisible = false
};

Button toggleEntryVisibilityButton = new Button
{
AutomationId = "ToggleEntryVisibilityButton",
Text = "Toggle Entry Visibility"
};

Button toggleEditorVisibilityButton = new Button
{
AutomationId = "ToggleEditorVisibilityButton",
Text = "Toggle Editor Visibility"
};

toggleEntryVisibilityButton.Clicked += (sender, e) => ToggleVisibility(toggleableEntry);
toggleEditorVisibilityButton.Clicked += (sender, e) => ToggleVisibility(toggleableEditor);

void ToggleVisibility(VisualElement element)
{
element.IsVisible = !element.IsVisible;
}

mainLayout.Children.Add(toggleableEntry);
mainLayout.Children.Add(toggleableEditor);
mainLayout.Children.Add(toggleEntryVisibilityButton);
mainLayout.Children.Add(toggleEditorVisibilityButton);

Content = mainLayout;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#if ANDROID || IOS // Desktop platforms do not have a soft keyboard, so the test is restricted to Android and iOS.
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue27236 : _IssuesUITest
{
public Issue27236(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "android allows type into hidden Entry control";

[Test, Order(1)]
[Category(UITestCategories.Entry)]
Copy link
Contributor

@jsuarezruiz jsuarezruiz Feb 6, 2025

Choose a reason for hiding this comment

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

Could happen the same issue with the SearchBar?, could you verify?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could happen the same issue with the SearchBar?, could you verify?

@jsuarezruiz,

No, the same behavior does not occur with the search bar. When the SearchBar's Visibility is set to Collapsed, it appropriately hides the keyboard as expected. This behavior has been applied consistently to Entry and Editor, ensuring uniform handling across these components.

public void VerifyEntryKeyboardVisibilityToggle()
{
App.WaitForElement("ToggleEntryVisibilityButton");
App.Tap("ToggleEntryVisibilityButton");
var element = App.WaitForElement("ToggleableEntry");
element.SendKeys("Hello, Entry");
App.Tap("ToggleEntryVisibilityButton");
var keyboardVisible = App.IsKeyboardShown();
Assert.That(keyboardVisible, Is.False);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we include a VerifyScreenshot to also check the Entry Visibility?

Copy link
Contributor Author

@prakashKannanSf3972 prakashKannanSf3972 Apr 14, 2025

Choose a reason for hiding this comment

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

As per your suggestion, I have included the VerifyScreenshot to validate the visibility of the editors. Let me know if you have any further concerns. Thanks!

VerifyScreenshot("VerifyEditorsNotVisible");
}

[Test, Order(2)]
[Category(UITestCategories.Editor)]
public void VerifyEditorKeyboardVisibilityToggle()
{
App.WaitForElement("ToggleEditorVisibilityButton");
App.Tap("ToggleEditorVisibilityButton");
var element = App.WaitForElement("ToggleableEditor");
element.SendKeys("Hello, Editor");
App.Tap("ToggleEditorVisibilityButton");
var keyboardVisible = App.IsKeyboardShown();
Assert.That(keyboardVisible, Is.False);
VerifyScreenshot("VerifyEditorsNotVisible");
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.