question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MudDatePicker with mask jump back caret on input in Server Side

See original GitHub issue

Bug type

Component

Component name

MudDatePicker

What happened?

When i develop local it not visible, but if publish on remote linux. Linux on low resources VM. I see how every cursor jumping back if i type quickly. <MudDatePicker Label="Date" @bind-Date="@DocDate" Editable="true" Clearable="true" Mask="@(new DateMask("dd.MM.yyyy"))" DateFormat="dd.MM.yyyy" > </MudDatePicker>

Expected behavior

In Remote ServerSide App if quickly type from keyboard date caret in field stay at end of input.

Reproduction link

https://try.mudblazor.com/snippet/cEcxOzkyxAkCxykM

Reproduction steps

  1. run server side app with datepicker with mask editable and clearable.
  2. in developer console browser set network type to slow 3g
  3. try quickly type from keyboard date. for example 12.12.12, result 12.12.1|2 or even worse like 1012002

Relevant log output

No response

Version (bug)

6.1.8

Version (working)

No response

What browsers are you seeing the problem on?

Firefox, Chrome, Microsoft Edge

On what operating system are you experiencing the issue?

Windows

Pull Request

  • I would like to do a Pull Request

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Issue Analytics

  • State:open
  • Created 5 months ago
  • Reactions:1
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dennmlcommented, Aug 18, 2023

@csuka1219 I was trying with

        protected override Task StringValueChanged(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {                
                if (DateTime.TryParseExact(value, DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime validDate))
                {
                    Date = validDate;
                }
            }

            return base.StringValueChanged(value);
        }

But the problem is that StringValueChanged is not invoked when I type into the MudDateField from your github sample. It is only invoked if the focus changes away from that component. If that was invoked when typing, it would set the Date value as soon as a valid date is typed. I can confirm that StringValueChanged does get invoked when typing if I set Mask like the commented line in your sample. However that causes the original issue where the caret jumps around with the mud masking; exactly the issue we’re trying to avoid. This seems to indicate that StringValueChanged does not get invoked by MudBlazor when typing if Mask is null. If we could change that so it does get invoked, I think your solution with cleave.js would work perfectly.

1reaction
dennmlcommented, Aug 17, 2023

For me it works well, the only problem is that i need to click out of the datepicker component’s focus to bind the value to the DateTime variable, I’m working on the solution of the problem.

Thanks @csuka1219 your solution is really appreciated. The masking works well for me with no cursor jumping but I also have the problem you mentioned. It does not bind until the element loses focus. In my case I need it to bind once the text is a valid date but I have not found a way to do that or access the string from blazor code. If you have any progress of tips I would be very grateful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date Picker
By setting the Mask parameter, an editable DatePicker can be used with any suitable input mask, preferrably a DateMask which has built-in date...
Read more >
React controlled input cursor jumps
This allows you to delegate the cursor positioning back to React, but make your async changes. Share.
Read more >
Cursor position when input mask is set [RESOLVED]
When I click into a field with a standard or custom mask applied, the cursor jumps to the position I've clicked. Or to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found