Skip to content

Commit 1afd090

Browse files
yacperArgoZhang
andauthored
fix(Search): DisplayText needs to be shown on first load (#6351)
* fix bug #6350 * refactor: 重构 OnSearch 参数更改为可为空 --------- Co-Authored-By: yacper <[email protected]> Co-authored-by: Argo Zhang <[email protected]>
1 parent e755e92 commit 1afd090

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/BootstrapBlazor/Components/Search/Search.razor.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public partial class Search<TValue>
133133
/// Gets or sets the callback delegate when the search button is clicked.
134134
/// </summary>
135135
[Parameter]
136-
public Func<string, Task<IEnumerable<TValue>>>? OnSearch { get; set; }
136+
public Func<string?, Task<IEnumerable<TValue>>>? OnSearch { get; set; }
137137

138138
/// <summary>
139139
/// Gets or sets the callback method to get display text. Default is null, using ToString() method.
@@ -200,13 +200,16 @@ protected override void OnParametersSet()
200200
NoDataTip ??= Localizer[nameof(NoDataTip)];
201201
_filterItems ??= [];
202202

203+
// 这里应该获得初始值
204+
_displayText = GetDisplayText(Value);
205+
203206
if (Debounce == 0)
204207
{
205208
Debounce = 200;
206209
}
207210
}
208211

209-
private string _displayText = "";
212+
private string? _displayText;
210213
private async Task OnSearchClick()
211214
{
212215
if (OnSearch != null)
@@ -226,7 +229,7 @@ private async Task OnSearchClick()
226229

227230
private async Task OnClearClick()
228231
{
229-
_displayText = "";
232+
_displayText = null;
230233
if (OnClear != null)
231234
{
232235
await OnClear();
@@ -247,7 +250,7 @@ private async Task OnClearClick()
247250
private async Task OnClickItem(TValue val)
248251
{
249252
CurrentValue = val;
250-
_displayText = GetDisplayText(val) ?? "";
253+
_displayText = GetDisplayText(val);
251254

252255
if (OnSelectedItemChanged != null)
253256
{

0 commit comments

Comments
 (0)