@using MudBlazor Rename @ItemType Cancel Rename @code { [CascadingParameter] IMudDialogInstance Dialog { get; set; } = null!; [Parameter] public string CurrentName { get; set; } = string.Empty; [Parameter] public string ItemType { get; set; } = "Item"; [Parameter] public bool RequireCsExtension { get; set; } = false; private string NewName { get; set; } = string.Empty; protected override void OnInitialized() { NewName = CurrentName; } private string LabelText => $"{ItemType} Name"; private string HelperText => RequireCsExtension ? "File must have .cs extension" : ""; private void Cancel() => Dialog.Cancel(); private void Submit() { if (string.IsNullOrWhiteSpace(NewName)) { return; } var name = NewName.Trim(); if (RequireCsExtension && !name.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)) { name += ".cs"; } if (name == CurrentName) { Cancel(); return; } Dialog.Close(DialogResult.Ok(name)); } private void HandleKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter") { Submit(); } else if (e.Key == "Escape") { Cancel(); } } }