Skip to content

Keyboard input doesn't work for InputDateType.DateTimeLocal #35498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SteveSandersonMS opened this issue Aug 19, 2021 · 0 comments · Fixed by #35682
Closed

Keyboard input doesn't work for InputDateType.DateTimeLocal #35498

SteveSandersonMS opened this issue Aug 19, 2021 · 0 comments · Fixed by #35682
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed feature-accessibility This issue has accessibility impact
Milestone

Comments

@SteveSandersonMS
Copy link
Member

Although <InputDate Type="@InputDateType.DateTimeLocal" @bind-Value="@someDate" /> works great with mouse input, it's not possible to use it with keyboard input.

This is quite strange because keyboard input does work for the other date types. From experimenting with this a bit, it seems that Chromium has some weird inconsistencies in how keyboard input is handled across the specialized date/time inputs, and it particularly goes wrong for us in the case of datetime-local because of a bad interaction with Blazor's @bind mechanism.

Scenario

<EditForm Model="@this">
    <p>Date: <InputDate Type="@InputDateType.Date" @bind-Value="@someDate" /></p>
    <p>Time: <InputDate Type="@InputDateType.Time" @bind-Value="@someDate" /></p>
    <p>Month: <InputDate Type="@InputDateType.Month" @bind-Value="@someDate" /></p>
    <p>DateTimeLocal: <InputDate Type="@InputDateType.DateTimeLocal" @bind-Value="@someDate" /></p>
    <p>You entered: @someDate</p>
</EditForm>

@code {
    DateTime someDate;
}

Expected: Should be able to type arbitrary data into any of these inputs using keyboard alone
Actual: It's possible for all of them except for DateTimeLocal, which behaves erratically

For example, try to type in any complete year such as 01/01/2000. I couldn't manage it. Sometimes (depending on what's already in the input) it auto-focuses-out when I enter either the day or month part, preventing me from continuing with the input. When the input was previously untouched, I get as far as the year part, and when I type in the third digit of 2000, it weirdly resets back from 01/01/--20 to 01/01/---2. Sometimes it resets after the first keystroke. I didn't figure out any combination of keystrokes that would get the date I wanted into the input.

What's going on

I haven't investigated the full sequence of events completely, but one thing I do know: these specialized date inputs raise change events a lot more often than you'd think! Once it contains a valid entry, every subsequent keystroke raises a change, which means Blazor is constantly trying to map the partial input back to a valid System.DateTime. If .NET's representation of that partial input is not the same JavaScript supplied, then the .NET side will overwrite the DOM state with its new representation, which probably leads to the interference.

I don't fully know why this only affects datetime-local and not the others. Maybe the others are lucky in that their partial input is always legal, or maybe datetime-local is the unlucky one due to some other quirk.

Fixing it

If it's possible to find a simple fix for this that's great. Maybe it's possible to have <InputDate> listen for a different event like blur/focusout depending on the Type. Maybe some other trick in the binding internals would handle it. If it turns out there isn't a good option, we still could remove the DateTimeLocal option from the InputDateType enum and recommend people who need datetime-local should bind it to a string and then do their own parsing later.

@SteveSandersonMS SteveSandersonMS added area-blazor Includes: Blazor, Razor Components feature-accessibility This issue has accessibility impact labels Aug 19, 2021
@pranavkm pranavkm added this to the 6.0-rc2 milestone Aug 19, 2021
@ghost ghost added the Working label Aug 24, 2021
@ghost ghost added Done This issue has been fixed and removed Working labels Aug 25, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 24, 2021
@mkArtakMSFT mkArtakMSFT added bug This issue describes a behavior which is not expected - a bug. and removed investigate labels Oct 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed feature-accessibility This issue has accessibility impact
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants