@using MudBlazor

<MudDialog>
    <DialogContent>
        <MudTextField @bind-Value="_password" Label="Password" InputType="InputType.Password"
                      Immediate="true" OnKeyDown="OnKeyDown" AutoFocus="true" />
    </DialogContent>
    <DialogActions>
        <MudButton OnClick="Cancel">Cancel</MudButton>
        <MudButton Color="Color.Primary" OnClick="Submit">OK</MudButton>
    </DialogActions>
</MudDialog>

@code {
    [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;

    private string _password = "";

    private void Submit() => MudDialog.Close(DialogResult.Ok(_password));
    private void Cancel() => MudDialog.Cancel();

    private void OnKeyDown(KeyboardEventArgs e)
    {
        if (e.Key == "Enter")
            Submit();
    }
}
