Skip to content

Commit e7c8897

Browse files
Update InputTextDialog.razor
1 parent e28585a commit e7c8897

1 file changed

Lines changed: 36 additions & 9 deletions

File tree

AudioCuesheetEditor/Shared/Dialogs/InputTextDialog.razor

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,20 @@ along with Foobar. If not, see
1818
@inherits BaseLocalizedComponent
1919

2020
@inject IStringLocalizer<InputTextDialog> _localizer
21+
@inject HotKeys _hotKeys
2122

2223
<MudDialog>
2324
<DialogContent>
24-
<MudTextField @bind-Value="inputValue" Label="@Label" Placeholder="@Placeholder" Variant="Variant.Outlined" />
25+
<MudTextField @bind-Value="inputValue" Label="@Label" Placeholder="@Placeholder" Variant="Variant.Outlined" Immediate OnKeyDown="TextFieldKeyDown" />
2526
</DialogContent>
2627
<DialogActions>
27-
<MudButton Color="Color.Success" Variant="Variant.Filled" OnClick="() => MudDialog?.Close(inputValue)">@_localizer["Ok"]</MudButton>
28+
<MudButton Color="Color.Success" Variant="Variant.Filled" OnClick="CloseDialogOk">@_localizer["Ok"]</MudButton>
2829
</DialogActions>
2930
</MudDialog>
3031

3132
@code {
32-
private string? inputValue;
33-
34-
protected override void OnParametersSet()
35-
{
36-
base.OnParametersSet();
37-
inputValue = InitialValue;
38-
}
33+
HotKeysContext? hotKeysContext;
34+
string? inputValue;
3935

4036
[CascadingParameter]
4137
private IMudDialogInstance? MudDialog { get; set; }
@@ -48,4 +44,35 @@ along with Foobar. If not, see
4844

4945
[Parameter]
5046
public String? InitialValue { get; set; }
47+
48+
protected override void OnInitialized()
49+
{
50+
base.OnInitialized();
51+
hotKeysContext = _hotKeys.CreateContext().Add(ModKey.None, Key.Enter, CloseDialogOk);
52+
}
53+
54+
protected override void Dispose(bool disposing)
55+
{
56+
base.Dispose(disposing);
57+
hotKeysContext?.DisposeAsync();
58+
}
59+
60+
protected override void OnParametersSet()
61+
{
62+
base.OnParametersSet();
63+
inputValue = InitialValue;
64+
}
65+
66+
void TextFieldKeyDown(KeyboardEventArgs args)
67+
{
68+
if (args.Key == "Enter")
69+
{
70+
CloseDialogOk();
71+
}
72+
}
73+
74+
void CloseDialogOk()
75+
{
76+
MudDialog?.Close(inputValue);
77+
}
5178
}

0 commit comments

Comments
 (0)