File tree Expand file tree Collapse file tree 5 files changed +94
-86
lines changed
src/BootstrapBlazor/Components/AutoComplete Expand file tree Collapse file tree 5 files changed +94
-86
lines changed Original file line number Diff line number Diff line change 1616 placeholder =" @PlaceHolder" disabled =" @Disabled" @ref =" FocusElement" />
1717 <span class =" form-select-append" ><i class =" @Icon" ></i ></span >
1818 <span class =" form-select-append ac-loading" ><i class =" @LoadingIcon" ></i ></span >
19- <DropdownMenu @ref =" _dropdown" ShowNoDataTip =" ShowNoDataTip" NoDataTip =" @NoDataTip"
20- OnItemClick =" @OnClickItem" Rows =" @Rows" ItemTemplate =" @ItemTemplate" ></DropdownMenu >
19+ <RenderTemplate ChildContent =" RenderItems" ></RenderTemplate >
2120</div >
21+
22+ @code {
23+ RenderFragment RenderDropdown =>
24+ @< ul class = " dropdown-menu" >
25+ @foreach (var item in Rows )
26+ {
27+ < li @key = " item" class = " dropdown-item" @onclick = " () => OnClickItem(item)" >
28+ @if (ItemTemplate == null )
29+ {
30+ < div > @item < / div >
31+ }
32+ else
33+ {
34+ @ItemTemplate (item )
35+ }
36+ < / li >
37+ }
38+ @if (ShowNoDataTip && Rows .Count == 0 )
39+ {
40+ < li class = " dropdown-item" > @NoDataTip < / li >
41+ }
42+ < / ul > ;
43+ }
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ public partial class AutoComplete
9090 private List < string > ? _filterItems ;
9191
9292 [ NotNull ]
93- private DropdownMenu ? _dropdown = default ;
93+ private AutoCompleteItems ? _dropdown = default ;
9494
9595 /// <summary>
9696 /// <inheritdoc/>
@@ -186,7 +186,15 @@ public override Task TriggerChange(string val)
186186 StateHasChanged ( ) ;
187187 }
188188 _render = true ;
189- _dropdown . Render ( Rows ) ;
189+ _dropdown . RenderContent ( ) ;
190190 return Task . CompletedTask ;
191191 }
192+
193+ private RenderFragment RenderItems => builder =>
194+ {
195+ builder . OpenComponent < AutoCompleteItems > ( 0 ) ;
196+ builder . AddAttribute ( 10 , "ChildContent" , RenderDropdown ) ;
197+ builder . AddComponentReferenceCapture ( 20 , dropdown => _dropdown = ( AutoCompleteItems ) dropdown ) ;
198+ builder . CloseComponent ( ) ;
199+ } ;
192200}
Original file line number Diff line number Diff line change 1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the Apache 2.0 License
3+ // See the LICENSE file in the project root for more information.
4+ // Maintainer: Argo Zhang([email protected] ) Website: https://www.blazor.zone 5+
6+ using Microsoft . AspNetCore . Components . Rendering ;
7+
8+ namespace BootstrapBlazor . Components ;
9+
10+ /// <summary>
11+ /// DropdownMenu component
12+ /// </summary>
13+ class AutoCompleteItems : IComponent
14+ {
15+ /// <summary>
16+ /// Gets or sets the child content
17+ /// </summary>
18+ [ Parameter , NotNull ]
19+ public RenderFragment ? ChildContent { get ; set ; }
20+
21+ private RenderHandle _renderHandle ;
22+
23+ /// <summary>
24+ /// <inheritdoc/>
25+ /// </summary>
26+ /// <param name="renderHandle"></param>
27+ public void Attach ( RenderHandle renderHandle )
28+ {
29+ _renderHandle = renderHandle ;
30+ }
31+
32+ /// <summary>
33+ /// <inheritdoc/>
34+ /// </summary>
35+ /// <param name="parameters"></param>
36+ /// <returns></returns>
37+ public Task SetParametersAsync ( ParameterView parameters )
38+ {
39+ parameters . SetParameterProperties ( this ) ;
40+
41+ RenderContent ( ) ;
42+ return Task . CompletedTask ;
43+ }
44+ /// <summary>
45+ /// Render method
46+ /// </summary>
47+ public void RenderContent ( )
48+ {
49+ _renderHandle . Render ( BuildRenderTree ) ;
50+ }
51+
52+ /// <summary>
53+ /// <inheritdoc/>
54+ /// </summary>
55+ /// <param name="builder"></param>
56+ private void BuildRenderTree ( RenderTreeBuilder builder )
57+ {
58+ builder . AddContent ( 0 , ChildContent ) ;
59+ }
60+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments