ui5-webcomponents icon indicating copy to clipboard operation
ui5-webcomponents copied to clipboard

DatePicker: abnormal display when setting a past date to maxDate

Open natsu0728 opened this issue 6 years ago • 2 comments

Describe the bug When I set the 'maxDate' prop of datePicker component with any date before today (the current date), the year becomes 0001, the 'value' prop is empty by default

To Reproduce Steps to reproduce the behavior:

  1. set 'dd/MM/YYYY' to formatPattern
  2. set any date before the current date to maxDate
  3. click the datePicker

Expected behavior the year should be the current year, not 0001

Screenshots image

natsu0728 avatar Sep 25 '20 08:09 natsu0728

Hello @natsu0728

This is the expected behavior of the ui5-datepicker. In order to understand it, I have created a CodeSandbox Sample, which shows how it woks.

By default if either min-date, max-date, or both are set, the initial focus of the datepicker goes to the first date, that can be selected. This can be as follows:

  • If only min-date is set, the focus will go to the value of min-date
  • If min-date and max-date are set, the focus will go to the value of min-date
  • If only max-date is set, the focus will go to the first date that can be selected, which is 01.01.0001.

In your case, you can use one of the following workarounds:

  • Set a min-date, so that the focus will not go the the first year.
  • Set the value of the datepicker to today/yesterday by default. This way, when the datepicker is opened, the focused date will be under your control.

fifoosid avatar Sep 25 '20 12:09 fifoosid

@fifoosid

If only max-date is set, the focus will go to the first date that can be selected, which is 01.01.0001.

In this case, I found that the focus goes to 01/01/0001 only when I set max-date with a past date. If the max-date is in the future (such as 30/09/2020), everything works well, though min-date is also not set. ps. Setting a value by default is a good solution for me, thanks !

natsu0728 avatar Sep 25 '20 13:09 natsu0728