@@ -8,7 +8,7 @@ namespace BootstrapBlazor.Components;
88/// <summary>
99/// DropdownItem 组件
1010/// </summary>
11- public class DropdownItem : ComponentBase , IDisposable
11+ public partial class DropdownItem
1212{
1313 /// <summary>
1414 /// 获得/设置 显示文本
@@ -32,7 +32,7 @@ public class DropdownItem : ComponentBase, IDisposable
3232 /// 获得/设置 是否被禁用回调方法 默认 null 优先级高于 <see cref="Disabled"/>
3333 /// </summary>
3434 [ Parameter ]
35- public Func < DropdownItem , bool > ? OnDisabledCallback { get ; set ; }
35+ public Func < bool > ? OnDisabledCallback { get ; set ; }
3636
3737 /// <summary>
3838 /// 获得/设置 点击回调方法 默认 null
@@ -46,45 +46,21 @@ public class DropdownItem : ComponentBase, IDisposable
4646 [ Parameter ]
4747 public RenderFragment ? ChildContent { get ; set ; }
4848
49- [ CascadingParameter ]
50- [ NotNull ]
51- private List < ComponentBase > ? Items { get ; set ; }
49+ private string ? ItemIconString => CssBuilder . Default ( "dropdown-item-icon" )
50+ . AddClass ( Icon , ! string . IsNullOrEmpty ( Icon ) )
51+ . Build ( ) ;
5252
53- /// <summary>
54- /// <inheritdoc/>
55- /// </summary>
56- protected override void OnInitialized ( )
57- {
58- base . OnInitialized ( ) ;
53+ private string ? ItemClassString => CssBuilder . Default ( "dropdown-item" )
54+ . AddClass ( "disabled" , CanTriggerClick )
55+ . Build ( ) ;
5956
60- Items . Add ( this ) ;
61- }
57+ private bool CanTriggerClick => OnDisabledCallback ? . Invoke ( ) ?? Disabled ;
6258
63- private bool _disposedValue ;
64-
65- /// <summary>
66- /// 释放资源方法
67- /// </summary>
68- /// <param name="disposing"></param>
69- protected virtual void Dispose ( bool disposing )
59+ private async Task OnClickItem ( )
7060 {
71- if ( ! _disposedValue )
61+ if ( OnClick != null )
7262 {
73- if ( disposing )
74- {
75- Items . Remove ( this ) ;
76- }
77-
78- _disposedValue = true ;
63+ await OnClick ( ) ;
7964 }
8065 }
81-
82- /// <summary>
83- /// <inheritdoc/>
84- /// </summary>
85- public void Dispose ( )
86- {
87- Dispose ( true ) ;
88- GC . SuppressFinalize ( this ) ;
89- }
9066}
0 commit comments