File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed
src/BootstrapBlazor/Components/Search Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change 5555 <Button Color =" SearchButtonColor" Text =" @SearchButtonText" Icon =" @ButtonIcon" OnClick =" OnSearchClick" aria-label =" Search" ></Button >
5656 }
5757 </div >
58- <ul class =" dropdown-menu" >
58+ <BootstrapBlazorRender @ref =" _dropdown" >
59+ @RenderDropdown
60+ </BootstrapBlazorRender >
61+ </div >
62+
63+ @code {
64+ RenderFragment RenderDropdown =>
65+ @< ul class = " dropdown-menu" >
5966 @foreach (var item in _filterItems )
6067 {
6168 < li class = " dropdown-item" @onclick = " () => OnClickItem(item)" >
7380 {
7481 < li class = " dropdown-item" > @NoDataTip < / li >
7582 }
76- </ul >
77- </ div >
83+ < / ul > ;
84+ }
Original file line number Diff line number Diff line change @@ -171,6 +171,9 @@ public partial class Search<TValue>
171171
172172 private SearchContext < TValue > _context = default ! ;
173173
174+ [ NotNull ]
175+ private BootstrapBlazorRender ? _dropdown = default ;
176+
174177 /// <summary>
175178 /// <inheritdoc/>
176179 /// </summary>
@@ -205,6 +208,14 @@ protected override void OnParametersSet()
205208 }
206209 }
207210
211+ private bool _render = true ;
212+
213+ /// <summary>
214+ /// <inheritdoc/>
215+ /// </summary>
216+ /// <returns></returns>
217+ protected override bool ShouldRender ( ) => _render ;
218+
208219 private string _displayText = "" ;
209220 /// <summary>
210221 /// 点击搜索按钮时触发此方法
@@ -280,11 +291,13 @@ private async Task OnClickItem(TValue val)
280291 [ JSInvokable ]
281292 public override async Task TriggerChange ( string val )
282293 {
294+ _render = false ;
283295 _displayText = val ;
284-
285296 if ( IsTriggerSearchByInput )
286297 {
287298 await OnSearchClick ( ) ;
288299 }
300+ _render = true ;
301+ _dropdown . Render ( ) ;
289302 }
290303}
You can’t perform that action at this time.
0 commit comments