Skip to content
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24930.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 24930, "The picker allows you to write text if the keyboard is visible", PlatformAffected.Android)]
public partial class Issue24930 : ContentPage
{
const string FirstPickerItem = "Baboon";
const string PickerId = "picker";
public Issue24930()
{
Picker picker = new Picker
{
AutomationId = PickerId,
Title = "Select a monkey"
};


picker.ItemsSource = new List<string>
{
FirstPickerItem,
"Capuchin Monkey"
};

Content = new StackLayout()
{
Children = { picker }
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#if ANDROID // This test is only for Android, Since the edit text is base view for Picker in Android
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;
namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue24930 : _IssuesUITest
{
const string FirstPickerItem = "Baboon";
const string PickerId = "picker";

public Issue24930(TestDevice device) : base(device) { }

public override string Issue => "The picker allows you to write text if the keyboard is visible";

// Key codes for "abcd"
int[] keyCodes = new int[]
{
29,30,31,32
};

[Test]
[Category(UITestCategories.Picker)]
public void PickerShouldNotAllowUserInputThroughKeyboard()
{
App.WaitForElement(PickerId);
App.Tap(PickerId);
App.WaitForElement(FirstPickerItem);
App.Back();
foreach (var keyCode in keyCodes)
{
App.SendKeys(keyCode);
}

VerifyScreenshot();
}

}
}
#endif
4 changes: 2 additions & 2 deletions src/Core/src/Platform/Android/PickerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public static void OnFocusChanged(bool gainFocus, EditText sender)

static void OnKeyPress(object? sender, AView.KeyEventArgs e)
{
//To prevent user from entering text when focus is received
e.Handled = true;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we'll want to handle every single keypress event.

This will probably break scenarios where a user has a hardware keyboard connected to the device and is trying to use tab to navigate components

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@PureWeen , Pressing the Tab key focuses on the EditText, causing the picker dialog to open. Navigation does not occur between the components. According to the implementation, a change in focus triggers the dialog to appear on the view. I have shared a video for reference. please let me know if you have any concerns.

Screen.Recording.2025-03-11.at.5.33.22.PM.mov

if (!AvailableKeys.Contains(e.KeyCode))
{
e.Handled = false;
return;
}
e.Handled = true;
(sender as AView)?.CallOnClick();
}

Expand Down
Loading