Skip to content

Commit

Permalink
[NavMenu] Revert fix for when prerender set to false (#2293)
Browse files Browse the repository at this point in the history
* [NavMenu] Revert fix for #2097. Needsa different/better solution
* [Demo] Make NavGroup.Expanded bindable
  • Loading branch information
vnbaaij authored Jun 28, 2024
1 parent 56dfe63 commit 8f57600
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
4 changes: 2 additions & 2 deletions examples/Demo/Shared/Shared/DemoNavMenuItem.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@using NavLink = FluentUI.Demo.Shared.NavLink

@switch(Value)
@switch (Value)
{
case NavGroup group:
<FluentNavGroup Expanded="@group.Expanded" Gap="@group.Gap" Icon="@group.Icon">
<FluentNavGroup @bind-Expanded="@group.Expanded" Gap="@group.Gap" Icon="@group.Icon" >
<TitleTemplate>
<h3>@group.Title</h3></TitleTemplate>
<ChildContent>
Expand Down
4 changes: 2 additions & 2 deletions examples/Demo/Shared/Shared/NavItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// MIT License - Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------------------

Expand Down Expand Up @@ -28,7 +28,7 @@ public NavLink(string? href, Icon icon, string title, NavLinkMatch match = NavLi

public record NavGroup : NavItem
{
public bool Expanded { get; init; }
public bool Expanded { get; set; }
public string Gap { get; init; }
public IReadOnlyList<NavItem> Children { get; }

Expand Down
19 changes: 1 addition & 18 deletions src/Core/Components/NavMenu/FluentNavGroup.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public partial class FluentNavGroup : FluentNavBase
private readonly RenderFragment _renderButton;
private bool _open;

private static int _renderCount = 0;
private static bool _negate = false;

protected string? ClassValue =>
new CssBuilder("fluent-nav-group")
.AddClass("fluent-nav-item")
Expand Down Expand Up @@ -105,30 +102,16 @@ public FluentNavGroup()
_renderButton = RenderButton;
}

protected override void OnInitialized()
{
_renderCount ++;
if (_renderCount > 1)
{
_negate = true;
}
}

private async Task ToggleExpandedAsync()
{

if (_negate)
{
Expanded = !Expanded;
}

if (!Owner.Expanded && Owner.CollapsedChildNavigation)
{
await SetExpandedAsync(!_open);
}
else
{
await SetExpandedAsync(Expanded);
await SetExpandedAsync(!Expanded);
}
}

Expand Down

0 comments on commit 8f57600

Please sign in to comment.