diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/Components/SelectListElement.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/Components/SelectListElement.razor.cs index 903d3e1..917c9a6 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/Components/SelectListElement.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/Components/SelectListElement.razor.cs @@ -10,10 +10,13 @@ public partial class SelectListElement [Parameter] public SelectListTheme Theme { get; set; } private async Task HandleItemClicked() { - if (Value != null) + if (Value == null) { - Value.IsSelected = true; - await ValueChanged.InvokeAsync(Value); + return; } + + Value.IsSelected = true; + StateHasChanged(); + await ValueChanged.InvokeAsync(Value); } } \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor index 69142f2..c9495fc 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor @@ -2,7 +2,7 @@ @using GameIdeas.BlazorApp.Shared.Components.Select.Components @typeparam TItem -
+
- @if (ContentVisile) + @if (IsContentOpen) {
@foreach (var item in Items) diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor.cs index 8af5bb8..5d5e07c 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor.cs @@ -12,32 +12,19 @@ public partial class MultipleSelectList [Parameter] public SelectListTheme Theme { get; set; } [Parameter] public bool AlignRight { get; set; } - private bool ContentVisile = false; - private SearchInput? SearchInput; - private bool ShouldClose = false; - - public void Open() => ContentVisile = true; - - public async Task Close() + private bool IsContentOpen { - await Task.Delay(TimeSpan.FromSeconds(0.2)); - - if (ShouldClose) - { - ContentVisile = false; - ShouldClose = false; - } + get => InputFocus || ContentFocus; } - public void Toggle() => ContentVisile = !ContentVisile; - - private async Task HandleFocusOut() => await Close(); - - private void HandleFocusIn() => Open(); + private bool InputFocus = false; + private bool ContentFocus = false; + private SearchInput? SearchInput; + private ElementReference ContentElement; + private ElementReference BaseElement; private async Task HandleItemClicked(SelectElement selectedValue) { - selectedValue.IsSelected = !selectedValue.IsSelected; Values = Items.Where(x => x.IsSelected && x.Item != null).Select(x => x.Item!); SearchInput?.SetText(string.Join(", ", Values)); await ValuesChanged.InvokeAsync(Values); @@ -45,29 +32,40 @@ public partial class MultipleSelectList private async Task HandleTextChanged() { - foreach (var item in Items) - { - item.IsSelected = false; - } + await BaseElement.FocusAsync(); + } - await Close(); - } - private void HandleContentFocusOut(Microsoft.AspNetCore.Components.Web.FocusEventArgs args) + private void HandleFocusIn() { - ShouldClose = true; - ContentVisile = false; + InputFocus = true; } - private void HandleContentFocusIn(Microsoft.AspNetCore.Components.Web.FocusEventArgs args) - { - ShouldClose = true; - } - private void HandleSearchClicked() - { - if (ContentVisile) - { - ShouldClose = false; - } - ContentVisile = !ContentVisile; + private void HandleContentFocusIn() + { + ContentFocus = true; + } + + private async Task HandleContentFocusOut() + { + await Task.Delay(TimeSpan.FromSeconds(0.3)); + ContentFocus = false; + } + + private async Task HandleFocusOut() + { + await Task.Delay(TimeSpan.FromSeconds(0.3)); + InputFocus = false; + } + + private async Task HandleSearchClicked() + { + if (!IsContentOpen) + { + await ContentElement.FocusAsync(); + } + else + { + await BaseElement.FocusAsync(); + } } } \ No newline at end of file