Browse Source
Merge pull request #2469 from AvaloniaUI/fixes/close-menu-if-clicked-when-open
Close Menu if Top Level item is clicked when already open
pull/2487/head
Steven Kirk
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
29 additions and
1 deletions
-
src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs
-
tests/Avalonia.Controls.UnitTests/Platform/DefaultMenuInteractionHandlerTests.cs
|
|
|
@ -336,7 +336,18 @@ namespace Avalonia.Controls.Platform |
|
|
|
|
|
|
|
if (e.MouseButton == MouseButton.Left && item?.HasSubMenu == true) |
|
|
|
{ |
|
|
|
Open(item, false); |
|
|
|
if (item.IsSubMenuOpen) |
|
|
|
{ |
|
|
|
if (item.IsTopLevel) |
|
|
|
{ |
|
|
|
CloseMenu(item); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Open(item, false); |
|
|
|
} |
|
|
|
|
|
|
|
e.Handled = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using Avalonia.Controls.Platform; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Interactivity; |
|
|
|
using Moq; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
@ -110,6 +111,22 @@ namespace Avalonia.Controls.UnitTests.Platform |
|
|
|
Assert.True(e.Handled); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Click_On_Open_TopLevel_Menu_Closes_Menu() |
|
|
|
{ |
|
|
|
var target = new DefaultMenuInteractionHandler(false); |
|
|
|
var menu = Mock.Of<IMenu>(); |
|
|
|
var item = Mock.Of<IMenuItem>(x => |
|
|
|
x.IsSubMenuOpen == true && |
|
|
|
x.IsTopLevel == true && |
|
|
|
x.HasSubMenu == true && |
|
|
|
x.Parent == menu); |
|
|
|
var e = new PointerPressedEventArgs { MouseButton = MouseButton.Left, Source = item }; |
|
|
|
|
|
|
|
target.PointerPressed(item, e); |
|
|
|
Mock.Get(menu).Verify(x => x.Close()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void PointerEnter_Opens_Item_When_Old_Item_Is_Open() |
|
|
|
{ |
|
|
|
|