diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/GitHub1650.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/GitHub1650.cs
new file mode 100644
index 000000000..d220285c3
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/GitHub1650.cs
@@ -0,0 +1,69 @@
+using System;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Github, 1650, "[macOS] Completed event of Entry raised on Tab key", PlatformAffected.macOS)]
+ public class GitHub1650 : TestContentPage
+ {
+ Label _completedCountLabel = new Label
+ {
+ Text = "Completed count: 0",
+ AutomationId = "CompletedCountLabel"
+ };
+
+ int _completedCount;
+ public int CompletedCount
+ {
+ get { return _completedCount; }
+ set
+ {
+ _completedCount = value;
+ _completedCountLabel.Text = $"Completed count: {value}";
+ }
+ }
+
+ protected override void Init()
+ {
+ // Setup our completed entry
+ var entry = new Entry
+ {
+ Placeholder = "Press enter here!",
+ AutomationId = "CompletedTargetEntry"
+ };
+ entry.Completed += (sender, e) =>
+ {
+ CompletedCount++;
+ };
+
+ StackLayout layout = new StackLayout();
+ layout.Children.Add(_completedCountLabel);
+ layout.Children.Add(entry);
+
+ Content = layout;
+ }
+
+#if UITEST
+#if __MACOS__
+ [Test]
+ public void GitHub1650Test()
+ {
+ RunningApp.WaitForElement(q => q.Marked("CompletedTargetEntry"));
+ RunningApp.Tap(q => q.Marked("CompletedTargetEntry"));
+
+ Assert.AreEqual(0, _completedCount, "Completed should not have been fired");
+
+ RunningApp.PressEnter();
+
+ Assert.AreEqual(1, _completedCount, "Completed should have been fired once");
+ }
+#endif
+#endif
+ }
+}
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 3121ebd94..be7eac1a6 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -773,6 +773,7 @@
+
diff --git a/Xamarin.Forms.Platform.MacOS/Renderers/EntryRenderer.cs b/Xamarin.Forms.Platform.MacOS/Renderers/EntryRenderer.cs
index 46390cd71..e31477ef8 100644
--- a/Xamarin.Forms.Platform.MacOS/Renderers/EntryRenderer.cs
+++ b/Xamarin.Forms.Platform.MacOS/Renderers/EntryRenderer.cs
@@ -11,6 +11,8 @@ namespace Xamarin.Forms.Platform.MacOS
{
public EventHandler FocusChanged;
+ public EventHandler Completed;
+
bool _windowEventsSet;
bool _disposed;
@@ -40,10 +42,18 @@ namespace Xamarin.Forms.Platform.MacOS
{
if (CurrentEditor != Window.FirstResponder)
FocusChanged?.Invoke(this, new BoolEventArgs(false));
-
+
base.DidEndEditing(notification);
}
+ public override void KeyUp(NSEvent theEvent)
+ {
+ base.KeyUp(theEvent);
+
+ if (theEvent.KeyCode == (ushort)NSKey.Return)
+ Completed?.Invoke(this, EventArgs.Empty);
+ }
+
protected override void Dispose(bool disposing)
{
if (disposing && !_disposed)
@@ -92,6 +102,7 @@ namespace Xamarin.Forms.Platform.MacOS
{
textField = new FormsNSTextField();
(textField as FormsNSTextField).FocusChanged += TextFieldFocusChanged;
+ (textField as FormsNSTextField).Completed += OnCompleted;
}
SetNativeControl(textField);
@@ -167,7 +178,10 @@ namespace Xamarin.Forms.Platform.MacOS
Control.EditingEnded -= OnEditingEnded;
var formsNSTextField = (Control as FormsNSTextField);
if (formsNSTextField != null)
+ {
formsNSTextField.FocusChanged -= TextFieldFocusChanged;
+ formsNSTextField.Completed -= OnCompleted;
+ }
}
}
@@ -193,6 +207,10 @@ namespace Xamarin.Forms.Platform.MacOS
void OnEditingEnded(object sender, EventArgs e)
{
ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);
+ }
+
+ void OnCompleted(object sender, EventArgs e)
+ {
EntryController?.SendCompleted();
}