-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FluentInputBase] Use
Debouncer
instead of PeriodicTimer
for debo…
…uncing `ValueChanged` handler with `ImmediateDelay`. (#2042) * fix(#2030): debounce using ImmediateDelay can throw an exception because of a race condition with PeriodicTimer. * feat: add `FluentSearch` demo for immediate use with debounce * chore: minor code clean for consistency
- Loading branch information
1 parent
106a711
commit c2a91f5
Showing
4 changed files
with
123 additions
and
43 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
examples/Demo/Shared/Pages/Search/Examples/SearchImmediate.razor
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,108 @@ | ||
<FluentStack Orientation="Orientation.Vertical" VerticalGap="10"> | ||
|
||
@* Immediate Delay *@ | ||
<FluentNumberField @bind-Value="_immediateDelay" | ||
TValue="int" | ||
Label="Immediate Delay" | ||
Placeholder="Delay" | ||
Min="0" | ||
Max="2000" | ||
Step="100" /> | ||
|
||
@* Search Box *@ | ||
<FluentSearch @bind-Value="_searchValue" | ||
@bind-Value:after="OnSearch" | ||
Immediate="true" | ||
ImmediateDelay="_immediateDelay" | ||
Placeholder="Search for name" /> | ||
|
||
@* Search Results *@ | ||
<p>You searched for: @_searchValue</p> | ||
<FluentListbox aria-label="search results" | ||
TOption="string" | ||
Items=@_searchResults | ||
SelectedOptionChanged="@(e => _searchValue = (e != _defaultResultsText ? e : string.Empty))" /> | ||
</FluentStack> | ||
|
||
@code { | ||
private string? _searchValue; | ||
private int _immediateDelay; | ||
|
||
private const string _defaultResultsText = "No results"; | ||
private List<string> _searchResults = DefaultResults(); | ||
|
||
private static List<string> DefaultResults() => new() { _defaultResultsText }; | ||
|
||
private void OnSearch() | ||
{ | ||
if (!string.IsNullOrWhiteSpace(_searchValue)) | ||
{ | ||
// You can also call an API here if the list is not local. | ||
var results = searchData | ||
.Where(str => str.Contains(_searchValue, StringComparison.OrdinalIgnoreCase)) | ||
.Select(str => str) | ||
.ToList(); | ||
|
||
_searchResults = results.Any() ? results : DefaultResults(); | ||
} | ||
else | ||
{ | ||
_searchResults = DefaultResults(); | ||
} | ||
} | ||
|
||
//This component is made for a lot of data. You can copy and paste a list with 6000 entries here https://sharetext.me/vfknowohwl" | ||
private List<string> searchData = new() | ||
{ | ||
"Alabama", | ||
"Alaska", | ||
"Arizona", | ||
"Arkansas", | ||
"California", | ||
"Colorado", | ||
"Connecticut", | ||
"Delaware", | ||
"Florida", | ||
"Georgia", | ||
"Hawaii", | ||
"Idaho", | ||
"Illinois", | ||
"Indiana", | ||
"Iowa", | ||
"Kansas", | ||
"Kentucky", | ||
"Louisiana", | ||
"Maine", | ||
"Maryland", | ||
"Massachussets", | ||
"Michigain", | ||
"Minnesota", | ||
"Mississippi", | ||
"Missouri", | ||
"Montana", | ||
"Nebraska", | ||
"Nevada", | ||
"New Hampshire", | ||
"New Jersey", | ||
"New Mexico", | ||
"New York", | ||
"North Carolina", | ||
"North Dakota", | ||
"Ohio", | ||
"Oklahoma", | ||
"Oregon", | ||
"Pennsylvania", | ||
"Rhode Island", | ||
"South Carolina", | ||
"South Dakota", | ||
"Texas", | ||
"Tennessee", | ||
"Utah", | ||
"Vermont", | ||
"Virginia", | ||
"Washington", | ||
"Wisconsin", | ||
"West Virginia", | ||
"Wyoming" | ||
}; | ||
} |
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
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
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