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.

KeyboardDatePicker doesn't work with date-fns format string

See original GitHub issue

If you don’t mind add a fun gif or meme, but no pressure

A GIF or MEME to give some spice of the internet

Environment

Tech Version
@material-ui/pickers ^3.2.1
material-ui ^4.1.1
React ^16.8.3
Browser Chrome 75
Peer library date-fns ^2.0.0-beta.1

Steps to reproduce

  1. Create KeyboardDatePicker with format="P"

Expected behavior

The docs for format just say “Format string”. It’s not clear to me what valid input for this format string is. I tried to use a date-fns format string, but that’s causing problems

My goal is to have a format string that respects the language setting of the user’s browser. E.g. I would like mm/dd/yyyy in English and dd/mm/yyyy in Spanish. date-fns has a format string P that accomplishes this. The browser’s Intl API would also do this, but there’s no way to use it in the format option since it only accepts a string

Actual behavior

I can only type one character in the input if format="P"

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
benmccanncommented, Aug 8, 2019

I didn’t look at that page and was only looking at https://material-ui-pickers.dev/api/KeyboardDatePicker, which I’d expect to mention something

Make sure that mask will be automatically generated from passed format. It’s recommended to use only robust formats for keyboard input.

I’m not sure I would have understood this. Putting mask in backticks to indicate it’s a property might be helpful. But mainly I’m not sure from the description how I’d make sure whether mask is being automatically generated or what is meant by robust formats.

1reaction
benmccanncommented, Aug 8, 2019

That worked! Thanks!

Feel free to close this issue. I’ll leave it open for the time being in case you want to update the docs at all. It might be helpful to add a note in the format docs specifying that mask may need to be set when changing the format

Thank you for all your help! Our app is now working and ready to bring green power to many more homes 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

KeyboardDatePicker doesn't work with date-fns format string
Actual behavior. I can only type one character in the input if format="P".
Read more >
Cannot get material-ui datepicker to work - Stack Overflow
Uncaught RangeError : Format string contains an unescaped latin ... No need to downgrade @date.io/date-fns, Just format Date properly as said ...
Read more >
Date-fns format and locale problem - The freeCodeCamp Forum
Hi, I used the sample from Material UI and tried to modify it. I am having a bit of trouble trying to do...
Read more >
https://auctions.truckandtrailer.co.za/res/dist/at...
node_modules/date-fns/esm/_lib/format/lightFormatters/index.js", "../../../. ... with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments.
Read more >
[Solved]-Cannot get material-ui datepicker to work-Reactjs
This happens as well if you pass undefined as format string. ... No need to downgrade @date.io/date-fns, Just format Date properly as said...
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