-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathDropdownInitializer.razor.cs
59 lines (45 loc) · 1.54 KB
/
DropdownInitializer.razor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Microsoft.AspNetCore.Components;
using Luthetus.Common.RazorLib.Dropdowns.Models;
using Luthetus.Common.RazorLib.Contexts.Displays;
namespace Luthetus.Common.RazorLib.Dropdowns.Displays;
public partial class DropdownInitializer : ComponentBase, IDisposable
{
[Inject]
private IDropdownService DropdownService { get; set; } = null!;
private ContextBoundary? _dropdownContextBoundary;
protected override void OnInitialized()
{
DropdownService.DropdownStateChanged += OnDropdownStateChanged;
base.OnInitialized();
}
private async Task ClearActiveKeyList()
{
var firstDropdown = DropdownService.GetDropdownState().DropdownList.FirstOrDefault();
if (firstDropdown is not null)
{
var restoreFocusOnCloseFunc = firstDropdown.RestoreFocusOnClose;
if (restoreFocusOnCloseFunc is not null)
await restoreFocusOnCloseFunc.Invoke();
}
DropdownService.ReduceClearAction();
}
private Task HandleOnFocusIn(DropdownRecord dropdown)
{
var localDropdownContextBoundary = _dropdownContextBoundary;
if (localDropdownContextBoundary is not null)
localDropdownContextBoundary.HandleOnFocusIn();
return Task.CompletedTask;
}
private Task HandleOnFocusOut(DropdownRecord dropdown)
{
return Task.CompletedTask;
}
public async void OnDropdownStateChanged()
{
await InvokeAsync(StateHasChanged);
}
public void Dispose()
{
DropdownService.DropdownStateChanged -= OnDropdownStateChanged;
}
}