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.

Datepicker defaultValue not being selected in the calendar when minDate is set

See original GitHub issue

Description

When creating a DatePicker component with minDate and defaultValue props set, the defaultValue is shown in the date text field, but not in the picker itself. The datepicker just shows the current day as the selected day.

I have tried this by setting the defaultValue prop equal to both a date object and a string. I have tried this using the value prop with no success. I have also tried to use the initialCalendarDate prop alongside value and/or defaultValue without success.

The interesting part is that the defaultValue or value prop will be selected in the calendar if a minDate is not set.

Images/Screenshots

In this case, the defaultValue is equal to “2/12/2017” from the store. image

Code Sample

<DatePicker
    id="campaign-start-date"
    label="Start Date"
    onChange={(dateString) => onStartDateChange(dateString)}
    minDate={new Date()}
    maxDate={new Date(new Date(endDate).getTime() - millisecondsPerDay)}
    initialCalendarDate={startDate}
    defaultValue={startDate}
    inline={true}
/>

startDate is equal to “2/12/2017” from the store endDate is equal to “2/20/2017” from the store onStartDateChange just changes the value of startDate in the store milisecondsPerDay is a const that equals 86400000 (this is so the max date can never be >= the endDate)

Version

  • React 15.4.2
  • React-MD 1.0.1

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mlaursencommented, Feb 8, 2017

Oh awesome! I think it was related to 53130fa

0reactions
adhesivewombatcommented, Feb 9, 2017

Yep! That’s the case. Good to know, I will make sure to use the value prop when I need control.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap Datetimepicker wrong default date with minDate
I see no issue in your fiddle ( minDate and maxDate are set to the given "hardcoded" value), while your snippet is missing...
Read more >
Default value datepicker not showing - jQuery Forum
I have the following datepicker function where I would like the DefaultDate to be displayed when opening the page.
Read more >
How to set default date of datepicker as first date of current ...
Hi every one as i have started jquery 5 days ago i was trying to set datepicker to default date as first date...
Read more >
KendoReact DatePicker Overview
Its features cover everything from setting a default value and selecting a date range to form validation and keyboard shortcuts. The DatePicker Component...
Read more >
react-date-picker - npm
Prop name Description Default value autoFocus Automatically focuses the input on mount. n/a calendarAriaLabel aria‑label for the calendar button. n/a clearAriaLabel aria‑label for the clear button....
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