react icon indicating copy to clipboard operation
react copied to clipboard

Bug: input type=date clears on Firefox when invalid date is typed

Open vasa-chi opened this issue 2 years ago • 8 comments

If you input incorrect value in date input on Firefox, the whole input clears. I've prepared a sandbox: https://codesandbox.io/s/cold-dawn-ksmgb4 . If you input 0 into any part (day, month, year) of the field, it goes to empty state.

React version: 18.2.0 Firefox: 110.0 macOS

Steps To Reproduce

  1. Fill date input with correct value
  2. Enter 0 into it
  3. The whole field clears

Link to code example: https://codesandbox.io/s/cold-dawn-ksmgb4

The current behavior

The field clears

The expected behavior

The field should behave the same as uncontrolled HTML input behaves (specifically, Firefox fills the date part with zeroes).

vasa-chi avatar Feb 16 '23 08:02 vasa-chi

This is by-default feature of input type=date, when your type=date so it's validate first and then display. So your input is 0 then validator check the given value is true or if false then it will print perfect date either it will print simple dd-mm-yyyy .

kalp2525 avatar Feb 22 '23 10:02 kalp2525

It isn't by default, and date inputs don't do that. You can play with it on MDN and see for yourself.

This is how Firefox handles 0 in month: изображение

Input's value in this state is "".

vasa-chi avatar Feb 22 '23 10:02 vasa-chi

This MDN given by you which was working perfect into my Firefox browser. I don't know why this not working in your Firefox browser. Please see the version of your browser and update it.

kalp2525 avatar Feb 22 '23 10:02 kalp2525

@kalp2525 What do you get, when you input 0 in month part of the input?

vasa-chi avatar Feb 22 '23 10:02 vasa-chi

image I getting this when my input 0 in month

kalp2525 avatar Feb 22 '23 10:02 kalp2525

I've checked FF 110.0 on macOS and Windows. Both give me this: изображение

Maybe this behaviour is locale-related? I'm on ru_RU

vasa-chi avatar Feb 22 '23 10:02 vasa-chi

I have FF 110.0 same like you so you check again and solve this issue.

kalp2525 avatar Feb 22 '23 10:02 kalp2525

This is happening for me as well. Here is a code sample https://github.com/jbonzohln/react-date-test I'm using Firefox 123 on macos 14.3.

jbonzohln avatar Mar 07 '24 22:03 jbonzohln

Hi,

you can try this way, using defaultValue

https://codesandbox.io/p/sandbox/competent-morning-jmwvr2?file=%2FApp.js%3A6%2C41

jtguignard avatar Apr 04 '24 07:04 jtguignard

That works only if the date input is bound to a single value like you have there, but if it's bound to a field within an object the issue is there. See https://codesandbox.io/p/sandbox/ecstatic-jerry-78z6dw

jbonzohln avatar Apr 05 '24 20:04 jbonzohln

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Jul 04 '24 21:07 github-actions[bot]

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

github-actions[bot] avatar Jul 11 '24 22:07 github-actions[bot]