-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #572 [HxSearchBox] Initial suggestions disappear when the DataP…
…rovider response is quick
- Loading branch information
Showing
2 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
@page "/HxSearchBox_Issue572_Test" | ||
|
||
<HxSearchBox TItem="SearchBoxItem" | ||
DataProvider="ProvideSearchResults" | ||
MinimumLength="0" | ||
Label="Search" | ||
ItemTitleSelector="(i) => i.Title" | ||
@bind-TextQuery="textQuery" | ||
ItemSelectionBehavior="SearchBoxItemSelectionBehavior.SelectAndReplaceTextQueryWithItemTitle" | ||
OnItemSelected="HandleItemSelected" | ||
OnTextQueryTriggered="HandleTextQueryTriggered"> | ||
<DefaultContentTemplate> | ||
<div class="small py-2 px-3 text-muted">Search for Mouse, Table or Door...</div> | ||
</DefaultContentTemplate> | ||
</HxSearchBox> | ||
|
||
<p>selectedItemTitle: @selectedItemTitle</p> | ||
<p>textQueryTriggered: @textQueryTriggered</p> | ||
<p>textQuery: @textQuery</p> | ||
|
||
@code { | ||
private string selectedItemTitle = string.Empty; | ||
private string textQueryTriggered = string.Empty; | ||
private string textQuery = string.Empty; | ||
private void HandleItemSelected(SearchBoxItem item) | ||
{ | ||
selectedItemTitle = item.Title; | ||
} | ||
private void HandleTextQueryTriggered(string text) | ||
{ | ||
textQueryTriggered = text; | ||
} | ||
List<SearchBoxItem> Data { get; set; } = new() | ||
{ | ||
new() | ||
{ | ||
Title = "Table", | ||
Subtitle = "$5000", | ||
Icon = BootstrapIcon.Table | ||
}, | ||
new() | ||
{ | ||
Title = "Mouse", | ||
Subtitle = "$40", | ||
Icon = BootstrapIcon.Mouse | ||
}, | ||
new() | ||
{ | ||
Title = "Door", | ||
Subtitle = "$100", | ||
Icon = BootstrapIcon.DoorClosed | ||
} | ||
}; | ||
|
||
Task<SearchBoxDataProviderResult<SearchBoxItem>> ProvideSearchResults(SearchBoxDataProviderRequest request) | ||
{ | ||
if (request.UserInput?.Length > 0) | ||
{ | ||
SearchBoxDataProviderResult<SearchBoxItem> result2 = new() | ||
{ | ||
Data = Data.Where(i => i.Title.Contains(request.UserInput, StringComparison.OrdinalIgnoreCase)).ToArray() | ||
}; | ||
return Task.FromResult(result2); | ||
} | ||
SearchBoxDataProviderResult<SearchBoxItem> result = new() | ||
{ | ||
Data = Data.Take(10).ToArray() | ||
}; | ||
return Task.FromResult(result); | ||
} | ||
|
||
record SearchBoxItem | ||
{ | ||
public string Title { get; set; } | ||
public string Subtitle { get; set; } | ||
public BootstrapIcon Icon { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters