mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-04 04:58:05 +08:00
fix(module: menu): active parent menu for routed links (#1134)
This commit is contained in:
parent
314b07daf9
commit
954461119e
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ namespace AntDesign
|
||||
{
|
||||
Menu.SelectItem(MenuItem);
|
||||
}
|
||||
else if (MenuItem.IsSelected)
|
||||
else if (!_isActive && MenuItem.IsSelected)
|
||||
{
|
||||
MenuItem.Deselect();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user