File tree Expand file tree Collapse file tree 3 files changed +48
-2
lines changed
src/BootstrapBlazor/Components/Dropdown Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change 5454 }
5555 else
5656 {
57- @ItemsTemplate
58- }
57+ <CascadingValue Value =" _items" IsFixed =" true" >
58+ @ItemsTemplate
59+ </CascadingValue >
60+ <RenderTemplate >
61+ @foreach( var item in _items )
62+ {
63+ if (item is DropdownDivider )
64+ {
65+ < Divider >< / Divider >
66+ }
67+ else if (item is DropdownItem t )
68+ {
69+ var disabled = GetItemTriggerClick (t );
70+ <DynamicElement @key =" t" class =" @GetItemClassString(disabled)"
71+ TriggerClick =" !disabled" OnClick =" () => OnClickItem(t)" >
72+ <i class =" @GetItemIconString(t)" ></i >
73+ <span >@t.Text </span >
74+ </DynamicElement >
75+ }
76+ }
77+ </RenderTemplate >
78+ }
5979 </div >
6080</div >
Original file line number Diff line number Diff line change @@ -205,6 +205,8 @@ public partial class Dropdown<TValue>
205205 /// </summary>
206206 private bool _isAsyncLoading ;
207207
208+ private readonly List < IDropdownItem > _items = [ ] ;
209+
208210 /// <summary>
209211 /// OnParametersSet 方法
210212 /// </summary>
@@ -290,4 +292,22 @@ private async Task HandlerClick()
290292 await OnClick . InvokeAsync ( ) ;
291293 }
292294 }
295+
296+ private static string ? GetItemIconString ( DropdownItem item ) => CssBuilder . Default ( "dropdown-item-icon" )
297+ . AddClass ( item . Icon , ! string . IsNullOrEmpty ( item . Icon ) )
298+ . Build ( ) ;
299+
300+ private static string ? GetItemClassString ( bool disabled ) => CssBuilder . Default ( "dropdown-item" )
301+ . AddClass ( "disabled" , disabled )
302+ . Build ( ) ;
303+
304+ private static bool GetItemTriggerClick ( DropdownItem item ) => item . OnDisabledCallback ? . Invoke ( item ) ?? item . Disabled ;
305+
306+ private static async Task OnClickItem ( DropdownItem item )
307+ {
308+ if ( item . OnClick != null )
309+ {
310+ await item . OnClick ( ) ;
311+ }
312+ }
293313}
Original file line number Diff line number Diff line change 99 margin-inline-start : 0.25rem ;
1010 }
1111}
12+
13+ .dropdown-menu {
14+ .divider {
15+ margin : 0.25rem 0 ;
16+ }
17+ }
You can’t perform that action at this time.
0 commit comments