fix dropdown

This commit is contained in:
Maxime Adler
2025-03-14 14:31:13 +01:00
parent 08ab5a091d
commit 237c88d38b
2 changed files with 38 additions and 9 deletions

View File

@@ -3,16 +3,17 @@
@typeparam TItem
<div class="select-list">
<div class="select-button" @onfocusin=HandleFocusIn>
<div class="select-button" @onfocusin=HandleFocusIn @onfocusout=HandleFocusOut>
<SearchInput @ref=SearchInput
Icon="SearchInputIcon.Dropdown"
TextChanged="HandleTextChanged"
ClearClicked="HandleTextChanged"
SearchClicked="Toggle" />
SearchClicked="HandleSearchClicked" />
</div>
<div @onfocusout=HandleFocusOut
class="select-container @(AlignRight ? "align-right" : "")"
tabindex="1000">
<div class="select-container @(AlignRight ? "align-right" : "")"
tabindex="1000"
@onfocusin=HandleContentFocusIn
@onfocusout=HandleContentFocusOut>
@if (ContentVisile)
{

View File

@@ -14,14 +14,24 @@ public partial class MultipleSelectList<TItem>
private bool ContentVisile = false;
private SearchInput? SearchInput;
private bool ShouldClose = false;
public void Open() => ContentVisile = true;
public void Close() => ContentVisile = false;
public async Task Close()
{
await Task.Delay(TimeSpan.FromSeconds(0.2));
if (ShouldClose)
{
ContentVisile = false;
ShouldClose = false;
}
}
public void Toggle() => ContentVisile = !ContentVisile;
private void HandleFocusOut() => Close();
private async Task HandleFocusOut() => await Close();
private void HandleFocusIn() => Open();
@@ -33,13 +43,31 @@ public partial class MultipleSelectList<TItem>
await ValuesChanged.InvokeAsync(Values);
}
private void HandleTextChanged()
private async Task HandleTextChanged()
{
foreach (var item in Items)
{
item.IsSelected = false;
}
Close();
await Close();
}
private void HandleContentFocusOut(Microsoft.AspNetCore.Components.Web.FocusEventArgs args)
{
ShouldClose = true;
ContentVisile = false;
}
private void HandleContentFocusIn(Microsoft.AspNetCore.Components.Web.FocusEventArgs args)
{
ShouldClose = true;
}
private void HandleSearchClicked()
{
if (ContentVisile)
{
ShouldClose = false;
}
ContentVisile = !ContentVisile;
}
}