@@ -22,16 +22,16 @@ along with Foobar. If not, see
2222
2323<MudDialog >
2424 <DialogContent >
25- <MudTextField @bind-Value =" inputValue " Label =" @Label" Placeholder =" @Placeholder" Variant =" Variant.Outlined" Immediate OnKeyDown =" TextFieldKeyDown" />
25+ <MudTextField @bind-Value =" _inputValue " Label =" @Label" Placeholder =" @Placeholder" Variant =" Variant.Outlined" Immediate OnKeyDown =" TextFieldKeyDown" />
2626 </DialogContent >
2727 <DialogActions >
2828 <MudButton Color =" Color.Success" Variant =" Variant.Filled" OnClick =" CloseDialogOk" >@_localizer ["Ok"]</MudButton >
2929 </DialogActions >
3030</MudDialog >
3131
3232@code {
33- HotKeysContext ? hotKeysContext ;
34- string ? inputValue ;
33+ HotKeysContext ? _hotKeysContext ;
34+ string ? _inputValue ;
3535
3636 [CascadingParameter ]
3737 private IMudDialogInstance ? MudDialog { get ; set ; }
@@ -43,36 +43,37 @@ along with Foobar. If not, see
4343 public string ? Placeholder { get ; set ; }
4444
4545 [Parameter ]
46- public String ? InitialValue { get ; set ; }
46+ public string ? InitialValue { get ; set ; }
4747
4848 protected override void OnInitialized ()
4949 {
5050 base .OnInitialized ();
51- hotKeysContext = _hotKeys .CreateContext ().Add (ModKey .None , Key .Enter , CloseDialogOk );
51+ _hotKeysContext = _hotKeys .CreateContext ().Add (ModKey .None , Key .Enter , CloseDialogOk );
5252 }
5353
5454 protected override void Dispose (bool disposing )
5555 {
5656 base .Dispose (disposing );
57- hotKeysContext ? .DisposeAsync ();
57+ _hotKeysContext ? .DisposeAsync ();
5858 }
5959
6060 protected override void OnParametersSet ()
6161 {
6262 base .OnParametersSet ();
63- inputValue = InitialValue ;
63+ _inputValue = InitialValue ;
6464 }
6565
6666 void TextFieldKeyDown (KeyboardEventArgs args )
6767 {
6868 if (args .Key == " Enter" )
6969 {
70- CloseDialogOk ();
70+ // Use a timer to close the dialog after a short delay to ensure that the keyboard event is fully processed before closing the dialog.
71+ new System .Threading .Timer (CloseDialogOk , null , 0 , 10 );
7172 }
7273 }
7374
74- void CloseDialogOk ()
75+ void CloseDialogOk (object ? state = null )
7576 {
76- MudDialog ? .Close (inputValue );
77+ MudDialog ? .Close (_inputValue );
7778 }
7879}
0 commit comments