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

Blazor requires double function calls to select parts of text - why?

$
0
0

I try to create custom component for DateOnly. I would like to select a part of the date that is active like belowe:

enter image description here

Now i want to change my CurrentValue (date) by 1 day if I press the button ArrowUp or ArrowDown and than i want to select some text.

private async Task OnKeyDownEvent(KeyboardEventArgs e)        {        preventDefault = true;        switch(e.Code)            {            case "ArrowUp":                {                if(CurrentValue != null)                    {                    CurrentValue = CurrentValue.Value.AddDays(1);                    }                break;                }            case "ArrowDown":                {                if(CurrentValue != null)                    {                    CurrentValue = CurrentValue.Value.AddDays(-1);                    }                break;                }            }        await JsRuntime.InvokeVoidAsync("SelectionPartOfText", ReferenceToInputDate, 0, 2);        await JsRuntime.InvokeVoidAsync("SelectionPartOfText", ReferenceToInputDate, 0, 2); //<- WHY I HAVE TO INVOKE THIS DOUBLE TIMES??        }

The problem is that if I don't call SelectionPartOfText twice as above, the date part will not be selected.Could You tell me why?

If I call Select Part Of Date at the beginning and then at the end of the OnKeyDownEvent function, it will be work too, but why i have to invoke twice?

Code belowe works too:

private async Task OnKeyDownEvent(KeyboardEventArgs e)        {        preventDefault = true;        await JsRuntime.InvokeVoidAsync("SelectionPartOfText", ReferenceToInputDate, 0, 2); //<-- FIRST (if I remove this part the function will stop working!)        switch(e.Code)            {            case "ArrowUp":                {                if(CurrentValue != null)                    {                    CurrentValue = CurrentValue.Value.AddDays(1);                    }                break;                }            case "ArrowDown":                {                if(CurrentValue != null)                    {                    CurrentValue = CurrentValue.Value.AddDays(-1);                    }                break;                }            }        await JsRuntime.InvokeVoidAsync("SelectionPartOfText", ReferenceToInputDate, 0, 2); //<- SECOUND (WHY I HAVE TO INVOKE THIS DOUBLE TIMES??)        }

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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