diff --git a/Terminal.Gui/Views/MessageBox.cs b/Terminal.Gui/Views/MessageBox.cs index cd14dfc4f..31b4a41ec 100644 --- a/Terminal.Gui/Views/MessageBox.cs +++ b/Terminal.Gui/Views/MessageBox.cs @@ -374,6 +374,10 @@ public static class MessageBox { Clicked = (int)btn.Data!; } + else + { + Clicked = defaultButton; + } e.Cancel = true; Application.RequestStop (); diff --git a/Tests/UnitTests/Dialogs/MessageBoxTests.cs b/Tests/UnitTests/Dialogs/MessageBoxTests.cs index 50765272f..c873686f7 100644 --- a/Tests/UnitTests/Dialogs/MessageBoxTests.cs +++ b/Tests/UnitTests/Dialogs/MessageBoxTests.cs @@ -504,5 +504,25 @@ public class MessageBoxTests Application.Run (top); top.Dispose (); } -} + [Theory] + [SetupFakeDriver] + [MemberData (nameof (AcceptingKeys))] + public void Button_IsDefault_True_Return_His_Index_On_Accepting (Key key) + { + Application.Init (); + + Application.Iteration += (_, _) => Assert.True (Application.RaiseKeyDownEvent (key)); + int res = MessageBox.Query ("hey", "IsDefault", "Yes", "No"); + + Assert.Equal (0, res); + + Application.Shutdown (); + } + + public static IEnumerable AcceptingKeys () + { + yield return [Key.Enter]; + yield return [Key.Space]; + } +}