Browse Source

Merge pull request #6151 from workgroupengineering/fixes/Issue_6100

Fixes issue 6100
pull/6187/head
Max Katz 5 years ago
committed by GitHub
parent
commit
9fc1490455
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Avalonia.Controls/ComboBox.cs
  2. 61
      tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs

2
src/Avalonia.Controls/ComboBox.cs

@ -205,7 +205,7 @@ namespace Avalonia.Controls
if (e.Handled)
return;
if (e.Key == Key.F4 ||
if ((e.Key == Key.F4 && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt) == false) ||
((e.Key == Key.Down || e.Key == Key.Up) && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt)))
{
IsDropDownOpen = !IsDropDownOpen;

61
tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs

@ -201,6 +201,65 @@ namespace Avalonia.Controls.UnitTests
}
}
}
[Fact]
public void Close_Window_On_Alt_F4_When_ComboBox_Is_Focus()
{
var inputManagerMock = new Moq.Mock<IInputManager>();
var services = TestServices.StyledWindow.With(inputManager: inputManagerMock.Object);
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var window = new Window();
window.KeyDown += (s, e) =>
{
if (e.Handled == false
&& e.KeyModifiers.HasAllFlags(KeyModifiers.Alt) == true
&& e.Key == Key.F4 )
{
e.Handled = true;
window.Close();
}
};
var count = 0;
var target = new ComboBox
{
Items = new[] { new Canvas() },
SelectedIndex = 0,
Template = GetTemplate(),
};
window.Content = target;
window.Closing +=
(sender, e) =>
{
count++;
};
window.Show();
target.Focus();
_helper.Down(target);
_helper.Up(target);
Assert.True(target.IsDropDownOpen);
target.RaiseEvent(new KeyEventArgs
{
RoutedEvent = InputElement.KeyDownEvent,
KeyModifiers = KeyModifiers.Alt,
Key = Key.F4
});
Assert.Equal(1, count);
}
}
}
}

Loading…
Cancel
Save