primeng icon indicating copy to clipboard operation
primeng copied to clipboard

DatePicker does not highlight defaultDate nor apply changes relative to it

Open Aaron-CityGIS opened this issue 1 month ago • 2 comments

Describe the bug

When looking at the PrimeNG docs for DatePicker it describers the following for the defaultDate property:

Image

When using defaultDate it does open with the correct month/year and time components, but no date is highlighted. Furthermore, when not picking any date and making changes in the time components it takes the current local date when deciding the date instead of applying them against the defaultDate:

Image

Note that adding a singular second to defaultDate causes it to pick the 1st of December 2025 as date component instead of the provided defaultDate value of December 17th 1995. The actual calendar is not updated to reflect this behavior.

Pull Request Link

No response

Reason for not contributing a PR

  • [x] Lack of time
  • [ ] Unsure how to implement the fix/feature
  • [ ] Difficulty understanding the codebase
  • [ ] Other

Other Reason

No response

Reproducer

https://stackblitz.com/edit/owyschma?file=src%2Fapp%2Fdate-picker-basic-demo.ts

Environment

Newest Angular and PrimeNG versions.

Angular version

20.3.14

PrimeNG version

v20

Node version

20.19.1

Browser(s)

No response

Steps to reproduce the behavior

  1. Add a p-datepicker with a defaultDate property, for example pointing to Date('1995-12-17T03:24:30Z')
  2. Click on the p-datepicker, allowing it to open its dialog
  3. Do not pick any date, instead click on any of the time component buttons, for example adding a second. The filled in date becomes current date instead of defaultDate

Expected behavior

I expect the defaultDate to be highlighted as described by the docs when opening the calendar and any changes made using the time component buttons to be relative against the defaultDate when no date has been manually picked using the calendar

Aaron-CityGIS avatar Dec 01 '25 12:12 Aaron-CityGIS

that is weird. simply based on the short defaultDate attribute description alone in the API page, i would also expect the expected behavior you mentioned. But also seems to be the primeng documentation being vague or lacking of details issue again.

The only way I was able to make the defaultDate variable show on the date-picker component was to do something like this.date = this.defaultDate in the constructor.

So this does seem like a bug in the sense that as the description of of the API for defaultDate does not work as described.

Also, Correct me if i'm wrong and I'm not an ui expert but at the same time this attribute looks redundant? Set the date to highlight on first opening if the field is blank. Why would a date be highlighted when datepicker opens when the form date is empty? wouldn't that give the user incorrect visual indication that a date is selected if it is highlighted?

ysk3a avatar Dec 01 '25 19:12 ysk3a

@ysk3a I assume/had hoped it was meant to work like the highlight you get for the current date. It has different coloring as opposed to a picked date. The issue with setting this.date, which I assume is bound to the p-datepicker model, is that it appears as actual user input, which could confuse the user. I had hoped to use defaultData as a 'starting point' without already setting a value in the model.

Aaron-CityGIS avatar Dec 02 '25 07:12 Aaron-CityGIS