Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Stop OnKeyDown event propagation

$
0
0

I have a MudTextField component which is bound to a decimal value and I want to erase the default 0 value when the user starts typing numbers. I've used the OnKeyDown event but I see it gets propagated even after I handle it and the number typed by the user gets inserted twice. args.StopPropagation does not seem to exist in Blazor or MudBlazor.

<MudTextField @bind-Value="_tripModel!.TripLength" Label="Length" Variant="Variant.Text" OnKeyDown="k => OnMileageKeyDown(k)"></MudTextField>private void OnMileageKeyDown(object args){    if (_tripModel!.TripLength == 0 && args is KeyboardEventArgs)    {        string keyChar = ((KeyboardEventArgs)args).Key;        bool success = int.TryParse(keyChar, out int keyInt);        if (success)        {            _tripModel!.TripLength = keyInt;            // ((KeyboardEventArgs)args).StopPropagation = true; // Not working            StateHasChanged();        }    }}

How can I stop event propagation?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>