Sync DebouncedTextField state with parent component changes

This commit is contained in:
Thorsten Sommer 2025-08-15 19:56:24 +02:00
parent 28b470f40b
commit e214f8ca8a
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -50,12 +50,14 @@ public partial class DebouncedTextField : MudComponentBase
private readonly Timer debounceTimer = new();
private string text = string.Empty;
private string lastParameterText = string.Empty;
#region Overrides of ComponentBase
protected override async Task OnInitializedAsync()
{
this.text = this.Text;
this.lastParameterText = this.Text;
this.debounceTimer.AutoReset = false;
this.debounceTimer.Interval = this.DebounceTime.TotalMilliseconds;
this.debounceTimer.Elapsed += (_, _) =>
@ -68,6 +70,19 @@ public partial class DebouncedTextField : MudComponentBase
await base.OnInitializedAsync();
}
protected override void OnParametersSet()
{
// Only sync when the parent's parameter actually changed since the last change:
if (this.Text != this.lastParameterText)
{
this.text = this.Text;
this.lastParameterText = this.Text;
this.debounceTimer.Stop();
this.debounceTimer.Start();
}
}
#endregion