Skip to content
Merged
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
24 changes: 24 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28121.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue28121">
<VerticalStackLayout>
<Picker Focused="Picker_Focused"
Unfocused="Picker_Unfocused"
AutomationId="picker">
<Picker.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Item1</x:String>
<x:String>Item2</x:String>
<x:String>Item3</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
<Label x:Name="FocusedLabel"
AutomationId="focusedLabel"
Text="Focused: false"/>
<Label x:Name="UnfocusedLabel"
AutomationId="unfocusedLabel"
Text="Unfocused: false"/>
</VerticalStackLayout>
</ContentPage>
21 changes: 21 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28121.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 28121, "Picker Focused/Unfocused Events Do Not Fire", PlatformAffected.Android)]

public partial class Issue28121 : ContentPage
{
public Issue28121()
{
InitializeComponent();
}

void Picker_Focused(object sender, FocusEventArgs e)
{
FocusedLabel.Text = "Focused: true";
}

void Picker_Unfocused(object sender, FocusEventArgs e)
{
UnfocusedLabel.Text = "Unfocused: true";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#if ANDROID
Copy link
Contributor

Choose a reason for hiding this comment

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

While the fix is for Android, I think the test could run on all the platforms and verify the same events everywhere. Could we remove the compilation directive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2025-03-03 at 14 27 56

It won't work because even with such addition

#if IOS
    App.Click("Done");
#endif

the iOS picker won't close

using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue28121 : _IssuesUITest
{

public Issue28121(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Picker Focused/Unfocused Events Do Not Fire";

[Test]
[Category(UITestCategories.Entry)]
[Category(UITestCategories.Compatibility)]
public void FocusAndUnfocusEventsShouldFire()
{
App.WaitForElement("picker");
App.Tap("picker");
App.WaitForElement("Item1");
App.Click("Item1");
var focusedLabelText = App.FindElement("focusedLabel").GetText();
var unfocusedLabelText = App.FindElement("unfocusedLabel").GetText();

Assert.That(focusedLabelText, Is.EqualTo("Focused: true"));
Assert.That(unfocusedLabelText, Is.EqualTo("Unfocused: true"));
}
}
#endif
8 changes: 6 additions & 2 deletions src/Core/src/Handlers/Picker/PickerHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ void OnClick(object? sender, EventArgs e)

_dialog.SetCanceledOnTouchOutside(true);

_dialog.DismissEvent += (sender, args) =>
_dialog.DismissEvent += OnDismiss;

void OnDismiss(object? s, EventArgs e)
{
_dialog.DismissEvent -= OnDismiss;
PlatformView?.ClearFocus();
_dialog = null;
};
}

_dialog.Show();
}
Expand Down