From b5195703836c8bf5954390f3f941937541a2a756 Mon Sep 17 00:00:00 2001 From: Peace Date: Wed, 10 Jul 2024 13:41:41 +0900 Subject: [PATCH] search 2 --- .../Pages/FormInputs/FormInputSearch.razor | 104 +++++++++++++++--- 1 file changed, 91 insertions(+), 13 deletions(-) diff --git a/BlazorFluentUI/Components/Pages/FormInputs/FormInputSearch.razor b/BlazorFluentUI/Components/Pages/FormInputs/FormInputSearch.razor index f9fec0d..cc25a1f 100644 --- a/BlazorFluentUI/Components/Pages/FormInputs/FormInputSearch.razor +++ b/BlazorFluentUI/Components/Pages/FormInputs/FormInputSearch.razor @@ -31,7 +31,7 @@ + SelectedOptionChanged="@(e => interactiveSearchValue = e != defaultResultsText ? e : string.Empty)"/>

You searched for: @interactiveSearchValue

@@ -47,31 +47,86 @@ + SelectedOptionChanged="@(e => debounceSearchValue = e != defaultResultsText ? e : string.Empty)" />

You searched for: @debounceSearchValue

-@code { - string? value; +Immediate (with and without debounce) + + + + +

You search for: @immediateSearchValue

+ +
+
+ +Display + + + + + +
+

Disabled

+ + + +
+
+

Read Only

+ + +
+
+

Icons

+ + + + + + + + + + +
+
+
+ + @code { + string? value; FluentSearch interactiveTest; string? interactiveSearchValue = string.Empty; - static string interactiveDefaultsText = "No results"; - static List defaultSearchResult() + static string defaultResultsText = "No results"; + static List GetDefaultSearchResult() { - return new List() { interactiveDefaultsText }; + return new List() { defaultResultsText }; } - List interactiveSearchResults = defaultSearchResult(); + List interactiveSearchResults = GetDefaultSearchResult(); void HandleSearchInput() { if (string.IsNullOrWhiteSpace(interactiveSearchValue)) { - interactiveSearchResults = defaultSearchResult(); + interactiveSearchResults = GetDefaultSearchResult(); interactiveSearchValue = string.Empty; } else @@ -178,7 +233,7 @@ } } - List debounceSearchResults = defaultSearchResult(); + List debounceSearchResults = GetDefaultSearchResult(); private void OnDebounceSearch() { @@ -193,13 +248,13 @@ } else { - debounceSearchResults = defaultSearchResult(); + debounceSearchResults = GetDefaultSearchResult(); } StateHasChanged(); } else { - debounceSearchResults = defaultSearchResult(); + debounceSearchResults = GetDefaultSearchResult(); StateHasChanged(); } } @@ -210,8 +265,31 @@ return; DisposeDebounceTimer(); - debounceSearchResults = defaultSearchResult(); + debounceSearchResults = GetDefaultSearchResult(); DebounceSearchValue = string.Empty; StateHasChanged(); } + + int immediateDelay; + string? immediateSearchValue; + + static List immediateSearchResults = GetDefaultSearchResult(); + + void OnImmediateSearch() + { + if (string.IsNullOrWhiteSpace(immediateSearchValue)) + { + immediateSearchResults = GetDefaultSearchResult(); + return; + } + + List temp = searchData + .Where(str => str.Contains(immediateSearchValue, StringComparison.OrdinalIgnoreCase)) + .Select(str => str) + .ToList(); + + immediateSearchResults = temp.Any() ? temp : GetDefaultSearchResult(); + } + + string? stateValue; }