diff --git a/src/BootstrapBlazor/Components/Nav/Nav.razor b/src/BootstrapBlazor/Components/Nav/Nav.razor index f3eeef9267c32bb18c1c2c9e4f4e7418d972d656..1a802e51d6600b327e7fa9b4ffdcfde48969e012 100644 --- a/src/BootstrapBlazor/Components/Nav/Nav.razor +++ b/src/BootstrapBlazor/Components/Nav/Nav.razor @@ -2,9 +2,9 @@ @inherits NavBase \ No newline at end of file + diff --git a/src/BootstrapBlazor/Components/Nav/NavBase.cs b/src/BootstrapBlazor/Components/Nav/NavBase.cs index c63670df96f0090f14567bfc75f5bd0e629b5c41..0b360e228887285a31b6f27e62f5a7dba1289c32 100644 --- a/src/BootstrapBlazor/Components/Nav/NavBase.cs +++ b/src/BootstrapBlazor/Components/Nav/NavBase.cs @@ -30,6 +30,7 @@ public abstract class NavBase : BootstrapComponentBase /// 获得/设置 组件数据源 /// [Parameter] + [NotNull] public IEnumerable? Items { get; set; } /// @@ -68,6 +69,16 @@ public abstract class NavBase : BootstrapComponentBase [Parameter] public RenderFragment? ChildContent { get; set; } + /// + /// OnParametersSet 方法 + /// + protected override void OnParametersSet() + { + base.OnParametersSet(); + + Items ??= Enumerable.Empty(); + } + /// /// 获得 NavLink 组件渲染内容 /// diff --git a/test/UnitTest/Components/NavTest.cs b/test/UnitTest/Components/NavTest.cs new file mode 100644 index 0000000000000000000000000000000000000000..7bf7bcbfe2ba1453555b06fa48ad480f3e55403e --- /dev/null +++ b/test/UnitTest/Components/NavTest.cs @@ -0,0 +1,130 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using Microsoft.AspNetCore.Components.Routing; + +namespace UnitTest.Components; + +public class NavTest : BootstrapBlazorTestBase +{ + [Fact] + public void Items_OK() + { + var cut = Context.RenderComponent