Skip to content

Commit

Permalink
Revert "feat(Layout): do not render Header/Footer if template is null (
Browse files Browse the repository at this point in the history
…dotnetcore#3946)"

This reverts commit 1b727d9.
  • Loading branch information
AiYuZhen committed Jul 31, 2024
1 parent 1b727d9 commit ebc5367
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.7.5-beta02</Version>
<Version>8.7.5-beta01</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
33 changes: 9 additions & 24 deletions src/BootstrapBlazor/Components/Layout/Layout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,48 @@
{
@if (IsAuthenticated)
{
<section @attributes="AdditionalAttributes" class="@ClassString" style="@StyleString">
<section @attributes="AdditionalAttributes" class="@ClassString">
@if (Side == null)
{
if(Header != null)
{
@RenderHeader(false)
}
@RenderHeader(false)
@RenderMain
@if (ShowFooter && Footer != null)
@if (ShowFooter)
{
@RenderFooter
}
}
else if (IsFullSide)
{
<aside class="@SideClassString" style="@SideStyleString">
@if(Side != null)
{
@Side
}
@Side
@if (Menus != null)
{
@RenderMenu(IsFullSide)
}
</aside>
<section class="layout-right">
@if(Header != null)
{
@RenderHeader(ShowCollapseBar)
}
@RenderHeader(ShowCollapseBar)
@RenderMain
@if (ShowFooter && Footer != null)
@if (ShowFooter)
{
@RenderFooter
}
</section>
}
else
{
@if (Header != null)
{
@RenderHeader(ShowCollapseBar)
}
@RenderHeader(ShowCollapseBar)
<section class="has-sidebar">
<aside class="@SideClassString" style="@SideStyleString">
@if (Side != null)
{
@Side
}
@Side
@if (Menus != null)
{
@RenderMenu(IsFullSide)
}
</aside>
@RenderMain
</section>
@if (ShowFooter && Footer != null)
@if (ShowFooter)
{
@RenderFooter
}
Expand Down
8 changes: 1 addition & 7 deletions src/BootstrapBlazor/Components/Layout/Layout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,10 @@ public partial class Layout : IHandlerException
private string? ClassString => CssBuilder.Default("layout")
.AddClass("has-sidebar", Side != null && IsFullSide)
.AddClass("is-page", IsPage)
.AddClass("has-footer", ShowFooter && Footer != null)
.AddClass("has-footer", ShowFooter)
.AddClassFromAttributes(AdditionalAttributes)
.Build();

private string? StyleString => CssBuilder.Default()
.AddClass("--bb-layout-header-height: 0px;", Header == null)
.AddClass("--bb-layout-footer-height: 0px;", ShowFooter == false || Footer == null)
.AddStyleFromAttributes(AdditionalAttributes)
.Build();

/// <summary>
/// 获得 页脚样式
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/BootstrapBlazor/Utils/JSModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace BootstrapBlazor.Components;
/// <summary>
/// 模块加载器
/// </summary>
/// <remarks>
/// 构造函数
/// </remarks>
/// <param name="jSObjectReference"></param>
public class JSModule(IJSObjectReference? jSObjectReference) : IAsyncDisposable
{
Expand Down
9 changes: 6 additions & 3 deletions test/UnitTest/Components/ButtonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ public async Task Tooltip_Ok()
var button = cut.FindComponent<Button>();
await cut.InvokeAsync(() => button.Instance.ShowTooltip());

button = cut.FindComponent<Button>();
button.SetParametersAndRender(pb =>
await cut.InvokeAsync(() =>
{
pb.Add(a => a.TooltipText, "Tooltip-Button");
var button = cut.FindComponent<Button>();
button.SetParametersAndRender(pb =>
{
pb.Add(a => a.TooltipText, "Tooltip-Button");
});
});
Assert.Equal("Tooltip-Button", cut.Instance.Title);

Expand Down
21 changes: 3 additions & 18 deletions test/UnitTest/Components/LayoutTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ public void ShowFooter_OK()

cut.SetParametersAndRender(pb => pb.Add(a => a.ShowFooter, false));
cut.WaitForAssertion(() => Assert.DoesNotContain("Footer", cut.Markup));

cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.ShowFooter, true);
pb.Add(a => a.Footer, (RenderFragment?)null);
});
cut.Contains("--bb-layout-footer-height: 0px;");
}

[Fact]
Expand Down Expand Up @@ -63,19 +56,13 @@ public void IsCollapsed_OK()
}

[Fact]
public async Task ShowCollapseBar_OK()
public void ShowCollapseBar_OK()
{
var cut = Context.RenderComponent<Layout>(pb =>
{
pb.Add(a => a.ShowCollapseBar, true);
pb.Add(a => a.Side, CreateSide());
});
cut.DoesNotContain("<i class=\"fa-solid fa-bars\"></i>");

cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.Header, CreateHeader());
});
Assert.Contains("<i class=\"fa-solid fa-bars\"></i>", cut.Markup);

var collapsed = false;
Expand All @@ -89,7 +76,7 @@ public async Task ShowCollapseBar_OK()
pb.Add(a => a.IsCollapsedChanged, v => collapsed = v);
});

await cut.InvokeAsync(() =>
cut.InvokeAsync(() =>
{
cut.Find("header > a").Click();
});
Expand Down Expand Up @@ -120,7 +107,6 @@ public void IsFullSide_OK()
pb.Add(a => a.IsFullSide, true);
pb.Add(a => a.Side, CreateSide());
pb.Add(a => a.ShowFooter, true);
pb.Add(a => a.Footer, CreateFooter());
pb.Add(a => a.ShowGotoTop, true);
pb.Add(a => a.Menus, new MenuItem[] { new() { Url = "/" } });
});
Expand Down Expand Up @@ -366,7 +352,6 @@ public void CollapseBarTemplate_Ok()
var cut = Context.RenderComponent<Layout>(pb =>
{
pb.Add(a => a.Side, CreateSide());
pb.Add(a => a.Header, CreateHeader());
pb.Add(a => a.IsFullSide, true);
pb.Add(a => a.ShowCollapseBar, true);
pb.Add(a => a.CollapseBarTemplate, builder =>
Expand Down Expand Up @@ -401,7 +386,7 @@ public void Authorized_Ok()
pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly });
pb.Add(a => a.OnAuthorizing, url => Task.FromResult(true));
});
cut.Contains("<section class=\"layout\" style=\"--bb-layout-header-height: 0px; --bb-layout-footer-height: 0px;\"><main class=\"layout-main\"></main></section>");
cut.Contains("<section class=\"layout\"><header class=\"layout-header\"></header><main class=\"layout-main\"></main></section>");
Context.DisposeComponents();
}
}

0 comments on commit ebc5367

Please sign in to comment.