Skip to content

Commit bd09928

Browse files
feat(Layout): add SideCollapsedWidth parameter (#8537)
* feat(Layout):增加SideCollapsedWidth参数用来处理菜单折叠时的宽度 feat(Layout):增加SideCollapsedWidth参数用来处理菜单折叠时的宽度 * feat(Layout):补充单元测试 test:补充单元测试 * doc: 增加版本信息 * refactor: 支持百分比等单位 * test: 重写单元测试 * chore: bump version 11.0.1 * refactor(NET11): suppress false positive analyzer warnings --------- Co-authored-by: Argo Zhang <argo@live.ca>
1 parent 505ff6c commit bd09928

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎src/BootstrapBlazor/BootstrapBlazor.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>11.0.1-beta03</Version>
4+
<Version>11.0.1</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

‎src/BootstrapBlazor/Components/Layout/Layout.razor.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ public partial class Layout : ITabHeader
229229
[Parameter]
230230
public string? SideWidth { get; set; }
231231

232+
/// <summary>
233+
/// <para lang="zh">指定侧边栏折叠时的宽度,使用 CSS 长度字符串。</para>
234+
/// <para lang="en">Specifies the width of the sidebar when collapsed, using a CSS length string.</para>
235+
/// <para>v<version>11.0.1</version></para>
236+
/// </summary>
237+
/// <remarks>接受任何有效的 CSS 长度值。为 null 时使用组件默认值。</remarks>
238+
[Parameter]
239+
public string? SideCollapsedWidth { get; set; }
240+
232241
/// <summary>
233242
/// <para lang="zh">获得/设置 Main 模板</para>
234243
/// <para lang="en">Gets or sets Main Template</para>
@@ -491,6 +500,7 @@ public partial class Layout : ITabHeader
491500
private string? StyleString => CssBuilder.Default()
492501
.AddClass("--bb-layout-header-height: 0px;", Header == null)
493502
.AddClass("--bb-layout-footer-height: 0px;", ShowFooter == false || Footer == null)
503+
.AddClass($"--bb-layout-sidebar-collapse-width: {SideCollapsedWidth};", IsCollapsed && SideCollapsedWidth != null)
494504
.AddStyleFromAttributes(AdditionalAttributes)
495505
.Build();
496506

‎test/UnitTest/Components/LayoutTest.cs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,26 @@ public void SideWidth_OK()
345345
cut.WaitForAssertion(() => Assert.DoesNotContain("width:", cut.Markup));
346346
}
347347

348+
[Fact]
349+
public void SideCollapsedWidth_OK()
350+
{
351+
var cut = Context.Render<Layout>(pb =>
352+
{
353+
pb.Add(a => a.IsCollapsed, false);
354+
pb.Add(a => a.SideCollapsedWidth, "80px");
355+
});
356+
cut.DoesNotContain("--bb-layout-sidebar-collapse-width");
357+
358+
cut.Render(pb => pb.Add(a => a.IsCollapsed, true));
359+
cut.Contains("--bb-layout-sidebar-collapse-width: 80px;");
360+
361+
cut.Render(pb => pb.Add(a => a.SideCollapsedWidth, "20%"));
362+
cut.Contains("--bb-layout-sidebar-collapse-width: 20%;");
363+
364+
cut.Render(pb => pb.Add(a => a.SideCollapsedWidth, null));
365+
cut.DoesNotContain("--bb-layout-sidebar-collapse-width");
366+
}
367+
348368
[Fact]
349369
public void UseTabSet_OK()
350370
{

0 commit comments

Comments
 (0)