File tree Expand file tree Collapse file tree 5 files changed +42
-30
lines changed
src/BootstrapBlazor/Components Expand file tree Collapse file tree 5 files changed +42
-30
lines changed Original file line number Diff line number Diff line change 11@namespace BootstrapBlazor.Components
22@inherits BootstrapComponentBase
33
4- <CascadingValue Value = this >
5- <nav @attributes = " @AdditionalAttributes " aria-label =" breadcrumb" >
6- <ol class = " breadcrumb " >
4+ <nav @attributes = " @AdditionalAttributes " aria-label = " breadcrumb " >
5+ <ol class =" breadcrumb" >
6+ <CascadingValue Value = " this " IsFixed = " true " >
77 @foreach ( var item in Value )
88 {
99 @RenderItem(item)
1010 }
11- </ol >
12- </nav >
13- </CascadingValue >
11+ </CascadingValue >
12+ </ol >
13+ </nav >
1414
1515@code {
1616 RenderFragment <BreadcrumbItem > RenderItem => item =>
17- @< li class = " @GetItemClassName(item) " aria - current = " @CurrentPage (item)" >
17+ @< li class = " @GetItemClassString (item)" >
1818 @if (! string .IsNullOrEmpty (item .Url ))
1919 {
2020 < a href = " @item.Url" > @item .Text < / a >
2424 @item .Text
2525 }
2626 < / li > ;
27- }
27+ }
Original file line number Diff line number Diff line change @@ -14,11 +14,20 @@ public sealed partial class Breadcrumb
1414 /// 获得/设置 数据集
1515 /// </summary>
1616 [ Parameter ]
17- public IEnumerable < BreadcrumbItem > Value { get ; set ; } = Enumerable . Empty < BreadcrumbItem > ( ) ;
17+ [ NotNull ]
18+ public IEnumerable < BreadcrumbItem > ? Value { get ; set ; }
1819
19- private string ? GetItemClassName ( BreadcrumbItem item ) => CssBuilder . Default ( "breadcrumb-item" )
20+ private static string ? GetItemClassString ( BreadcrumbItem item ) => CssBuilder . Default ( "breadcrumb-item" )
21+ . AddClass ( item . CssClass )
2022 . Build ( ) ;
2123
22- private string ? CurrentPage ( BreadcrumbItem item ) => CssBuilder . Default ( )
23- . Build ( ) ;
24+ /// <summary>
25+ /// <inheritdoc/>
26+ /// </summary>
27+ protected override void OnParametersSet ( )
28+ {
29+ base . OnParametersSet ( ) ;
30+
31+ Value ??= [ ] ;
32+ }
2433}
Original file line number Diff line number Diff line change 66namespace BootstrapBlazor . Components ;
77
88/// <summary>
9- /// BreadcrumbItem 实体类
9+ /// BreadcrumbItem Class
1010/// </summary>
11- public class BreadcrumbItem
11+ /// <param name="text"></param>
12+ /// <param name="url"></param>
13+ /// <param name="cssClass"></param>
14+ public class BreadcrumbItem ( string text , string ? url = null , string ? cssClass = null )
1215{
1316 /// <summary>
14- /// 获得/设置 导航地址
17+ /// 获得/设置 显示文字
1518 /// </summary>
16- public string ? Url { get ; }
19+ public string Text { get ; } = text ;
1720
1821 /// <summary>
19- /// 获得/设置 显示文字
22+ /// 获得/设置 导航地址
2023 /// </summary>
21- public string Text { get ; }
24+ public string ? Url { get ; } = url ;
2225
2326 /// <summary>
24- /// 构造函数
27+ /// 获得/设置 样式名称
2528 /// </summary>
26- /// <param name="text"></param>
27- /// <param name="url"></param>
28- public BreadcrumbItem ( string text , string ? url = null )
29- {
30- Text = text ;
31- Url = url ;
32- }
29+ public string ? CssClass { get ; } = cssClass ;
3330}
Original file line number Diff line number Diff line change @@ -22,10 +22,8 @@ public partial class Button : ButtonBase
2222 protected ElementReference ButtonElement { get ; set ; }
2323
2424 /// <summary>
25- /// OnAfterRenderAsync 方法
25+ /// <inheritdoc/>
2626 /// </summary>
27- /// <param name="firstRender"></param>
28- /// <returns></returns>
2927 protected override async Task OnAfterRenderAsync ( bool firstRender )
3028 {
3129 await base . OnAfterRenderAsync ( firstRender ) ;
Original file line number Diff line number Diff line change @@ -13,14 +13,15 @@ public void ButtonStyle_Ok()
1313 var DataSource = new List < BreadcrumbItem >
1414 {
1515 new ( "Library" ) ,
16- new ( "Data" )
16+ new ( "Data" , "" , "cssClass" )
1717 } ;
1818
1919 var cut = Context . RenderComponent < Breadcrumb > ( pb =>
2020 {
2121 pb . Add ( b => b . Value , DataSource ) ;
2222 } ) ;
2323 Assert . Contains ( "Library" , cut . Markup ) ;
24+ Assert . Contains ( "class=\" breadcrumb-item cssClass\" " , cut . Markup ) ;
2425 Assert . DoesNotContain ( "href" , cut . Markup ) ;
2526
2627 DataSource . Add ( new BreadcrumbItem ( "Home" , "https://www.blazor.zone/" ) ) ;
@@ -35,5 +36,12 @@ public void ButtonStyle_Ok()
3536 {
3637 pb . Add ( b => b . AdditionalAttributes , new Dictionary < string , object > ( ) { [ "tag" ] = "tagok" } ) ;
3738 } ) ;
39+ cut . Contains ( "tag=\" tagok\" " ) ;
40+
41+ cut . SetParametersAndRender ( pb =>
42+ {
43+ pb . Add ( b => b . Value , null ) ;
44+ } ) ;
45+ Assert . DoesNotContain ( "li" , cut . Markup ) ;
3846 }
3947}
You can’t perform that action at this time.
0 commit comments