Skip to content

Commit 228b7bf

Browse files
Fixed picker allows user input if the keyboard is visible (#26382)
* Fixed The picker allows you to write text if the keyboard is visible * Modified test case and image Some times the text is entered in entry instead of picker * Fixed test case failure with diff approach * updated code changes * modified code changes * Fixed The picker allows you to write text if the keyboard is visible * Modified test case and image Some times the text is entered in entry instead of picker * Fixed test case failure with diff approach * updated code changes * modified code changes
1 parent 00315fa commit 228b7bf

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed
7.98 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
[Issue(IssueTracker.Github, 24930, "The picker allows you to write text if the keyboard is visible", PlatformAffected.Android)]
4+
public partial class Issue24930 : ContentPage
5+
{
6+
const string FirstPickerItem = "Baboon";
7+
const string PickerId = "picker";
8+
public Issue24930()
9+
{
10+
Picker picker = new Picker
11+
{
12+
AutomationId = PickerId,
13+
Title = "Select a monkey"
14+
};
15+
16+
17+
picker.ItemsSource = new List<string>
18+
{
19+
FirstPickerItem,
20+
"Capuchin Monkey"
21+
};
22+
23+
Content = new StackLayout()
24+
{
25+
Children = { picker }
26+
};
27+
}
28+
}
29+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#if ANDROID // This test is only for Android, Since the edit text is base view for Picker in Android
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
public class Issue24930 : _IssuesUITest
8+
{
9+
const string FirstPickerItem = "Baboon";
10+
const string PickerId = "picker";
11+
12+
public Issue24930(TestDevice device) : base(device) { }
13+
14+
public override string Issue => "The picker allows you to write text if the keyboard is visible";
15+
16+
// Key codes for "abcd"
17+
int[] keyCodes = new int[]
18+
{
19+
29,30,31,32
20+
};
21+
22+
[Test]
23+
[Category(UITestCategories.Picker)]
24+
public void PickerShouldNotAllowUserInputThroughKeyboard()
25+
{
26+
App.WaitForElement(PickerId);
27+
App.Tap(PickerId);
28+
App.WaitForElement(FirstPickerItem);
29+
App.Back();
30+
foreach (var keyCode in keyCodes)
31+
{
32+
App.SendKeys(keyCode);
33+
}
34+
35+
VerifyScreenshot();
36+
}
37+
38+
}
39+
}
40+
#endif

src/Core/src/Platform/Android/PickerManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public static void OnFocusChanged(bool gainFocus, EditText sender)
4040

4141
static void OnKeyPress(object? sender, AView.KeyEventArgs e)
4242
{
43+
//To prevent user from entering text when focus is received
44+
e.Handled = true;
4345
if (!AvailableKeys.Contains(e.KeyCode))
4446
{
45-
e.Handled = false;
4647
return;
4748
}
48-
e.Handled = true;
4949
(sender as AView)?.CallOnClick();
5050
}
5151

0 commit comments

Comments
 (0)