From a0036da781596adae2bcb80d5b257a609b998f7e Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Thu, 3 Apr 2025 12:54:51 +0200 Subject: [PATCH] Fix search widget click outside behavior (#760) --- .../Components/Widgets/SearchWidget.razor | 126 +++++++++--------- 1 file changed, 65 insertions(+), 61 deletions(-) diff --git a/src/AliasVault.Client/Main/Components/Widgets/SearchWidget.razor b/src/AliasVault.Client/Main/Components/Widgets/SearchWidget.razor index 1525e30c9..d7b5aac6d 100644 --- a/src/AliasVault.Client/Main/Components/Widgets/SearchWidget.razor +++ b/src/AliasVault.Client/Main/Components/Widgets/SearchWidget.razor @@ -4,79 +4,80 @@ @inject JsInteropService JsInteropService @implements IAsyncDisposable -
- + +
+ - @if (ShowHelpText) - { -
- @if (string.IsNullOrEmpty(SearchTerm)) - { -

Type a term to search for, this can be the service name, description or email address.

- } - else if (SearchTerm.Length == 1) - { -

Please type more chars

- } - else - { -

Searching for "@SearchTerm"

- } -
- } - - @if (ShowResults) - { - @if (SearchResults.Any()) + @if (ShowHelpText) { -
- @for (int i = 0; i < SearchResults.Count; i++) +
+ @if (string.IsNullOrEmpty(SearchTerm)) { - var result = SearchResults[i]; -
- -
-
@result.Service.Name
- @if (!string.IsNullOrEmpty(result.Alias.Email)) - { - (@result.Alias.Email) - } - else if (!string.IsNullOrEmpty(result.Username)) - { - (@result.Username) - } -
-
+

Type a term to search for, this can be the service name, description or email address.

+ } + else if (SearchTerm.Length == 1) + { +

Please type more chars

+ } + else + { +

Searching for "@SearchTerm"

}
} - else + + @if (ShowResults && SearchTerm.Length >= 2) { -
-
- No results found + @if (SearchResults.Any()) + { +
+ @for (int i = 0; i < SearchResults.Count; i++) + { + var result = SearchResults[i]; +
+ +
+
@result.Service.Name
+ @if (!string.IsNullOrEmpty(result.Alias.Email)) + { + (@result.Alias.Email) + } + else if (!string.IsNullOrEmpty(result.Username)) + { + (@result.Username) + } +
+
+ }
-
+ } + else + { +
+
+ No results found +
+
+ } } - } -
+
+ @code { private string SearchTerm { get; set; } = string.Empty; private List SearchResults { get; set; } = new(); - private bool ShowResults => SearchTerm.Length >= 2; + private bool ShowResults { get; set; } private bool ShowHelpText { get; set; } private int SelectedIndex { get; set; } = -1; @@ -102,11 +103,13 @@ private void OnFocus() { ShowHelpText = true; + ShowResults = true; } - private void OnBlur() + private void OnClose() { ShowHelpText = false; + ShowResults = false; } private async Task SearchTermChanged(ChangeEventArgs e) @@ -182,6 +185,7 @@ SearchTerm = string.Empty; SearchResults.Clear(); StateHasChanged(); + OnClose(); } private async Task FocusSearchField()