Skip to content

Commit 45923b9

Browse files
committed
refactor: 重构 OnSearch 参数更改为可为空
1 parent 27aec39 commit 45923b9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 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.
@@ -209,7 +209,7 @@ protected override void OnParametersSet()
209209
}
210210
}
211211

212-
private string _displayText = "";
212+
private string? _displayText;
213213
private async Task OnSearchClick()
214214
{
215215
if (OnSearch != null)
@@ -229,7 +229,7 @@ private async Task OnSearchClick()
229229

230230
private async Task OnClearClick()
231231
{
232-
_displayText = "";
232+
_displayText = null;
233233
if (OnClear != null)
234234
{
235235
await OnClear();
@@ -250,7 +250,7 @@ private async Task OnClearClick()
250250
private async Task OnClickItem(TValue val)
251251
{
252252
CurrentValue = val;
253-
_displayText = GetDisplayText(val) ?? "";
253+
_displayText = GetDisplayText(val);
254254

255255
if (OnSelectedItemChanged != null)
256256
{

0 commit comments

Comments
 (0)