matheo / angular

Open Source Angular Libraries: MatDataSource, MatDatepicker
http://matheo.co/demos/
MIT License
60 stars 15 forks source link

Expose the users pre-selected dateTime value whenever a pre-selection is made #59

Open nate-kumar opened 2 years ago

nate-kumar commented 2 years ago

Firstly, thank you for creating this library specifically for the date-time picker implementation; it is surprising that Angular material hasn't addressed this after 4 years of requests! Your implementation feels right at home alongside other material components and works beautifully :)

One aspect which I feel makes use of the library difficult however is the lack of emitted Date values whenever the user is navigating through views. Specifically take the following typical flow:

  1. Open date-time picker (component initialises with new Date() -> Mon May 09 2022 12:34:56)
  2. Select a date (e.g. 10th May 2022 -> Tue May 10 2022 00:00:00)
  3. Select an hour (e.g. 17:00 -> Tue May 10 2022 17:00:00)
  4. Select a minute (e.g. 30 -> Tue May 10 2022 17:30:00)
  5. Apply (using a button with the matDatepickerApply directive)

I would expect to be able to access a Date object which contains the currently highlighted date emitted each time the user makes a selection (steps 2, 3 and 4) and ideally is initialised with the value that the datepicker displays when opened (step 1). To my knowledge there is no way to access this value using the APIs provided. This means in practice that I have no way of knowing what the user has selected until step 5 at which point Tue May 10 2022 17:30:00 is correctly emitted via (dateChange).

There are concrete drawbacks to not having this information being made available, mainly in providing a unified user experience within the component and in other related components. For example:

The ideal implementation would expose the following APIs at minimum (arbitrary names) in much the same way that the dateChange interface works:

Note: The first image demonstrates the scenario in which it would be beneficial to disable the 'Select' button as the currently highlighted date is clearly out of valid range. The button would be reenabled on highlighting a valid date, as in the second image image image

Please let me know your thoughts and thanks again for the library!