fix(module: menu): active parent menu for routed links (#1134)

This commit is contained in:
Andrzej Bakun 2021-02-14 10:26:54 +01:00 committed by GitHub
parent 314b07daf9
commit 954461119e
3 changed files with 12 additions and 7 deletions

View File

@ -128,6 +128,7 @@ namespace AntDesign
return;
}
var selectedKeys = new List<string>();
bool skipParentSelection = false;
if (!Multiple)
{
foreach (MenuItem menuitem in MenuItems.Where(x => x != item))
@ -139,14 +140,16 @@ namespace AntDesign
}
else if (menuitem.IsSelected || menuitem.FirstRun)
{
menuitem.Deselect();
if (!menuitem.FirstRun)
skipParentSelection = item.ParentMenu?.Key == menuitem.ParentMenu?.Key;
menuitem.Deselect(skipParentSelection);
}
}
}
if (!item.IsSelected)
{
item.Select();
item.Select(skipParentSelection);
}
selectedKeys.Add(item.Key);
_selectedKeys = selectedKeys.ToArray();

View File

@ -116,18 +116,20 @@ namespace AntDesign
}
}
public void Select()
public void Select(bool skipParentSelection = false)
{
IsSelected = true;
FirstRun = false;
ParentMenu?.Select();
if (!skipParentSelection)
ParentMenu?.Select();
}
public void Deselect()
public void Deselect(bool sameParentAsSelected = false)
{
IsSelected = false;
FirstRun = false;
ParentMenu?.Deselect();
if (!sameParentAsSelected)
ParentMenu?.Deselect();
}
}
}

View File

@ -105,7 +105,7 @@ namespace AntDesign
{
Menu.SelectItem(MenuItem);
}
else if (MenuItem.IsSelected)
else if (!_isActive && MenuItem.IsSelected)
{
MenuItem.Deselect();
}