material-ui-pickers icon indicating copy to clipboard operation
material-ui-pickers copied to clipboard

[DateTimePicker] Always show the "OK" button

Open debojyoti opened this issue 6 years ago • 6 comments

Hey guys, first of all thanks for the great work with v4, it's awesome!

I am currently using "@material-ui/pickers": "^4.0.0-alpha.4" So in my implementation of date-time picker, time selection is not always mandatory, users can skip it, so there is a requirement to capture the change also when a date is being selected and the picker is dismissed from the time screen.

So I can see in the doc that onMonthChange and onYearChange is available, but onDateChange will be really helpful

debojyoti avatar Apr 10 '20 16:04 debojyoti

  • @debojyoti I don't understand, what's wrong with the usage of an onChange prop only?
  • @dmtrKovalenko I don't understand the motivation for the existence of the onMonthChange and onYearChange prop. Would it be possible to remove these props?

oliviertassinari avatar Apr 12 '20 20:04 oliviertassinari

@oliviertassinari I think no, because some users are tracking information about how users are using datepickers. Also, it can be useful to somehow change the UI accordingly to the selected month or year.

dmtrKovalenko avatar Apr 13 '20 07:04 dmtrKovalenko

@dmtrKovalenko Right, I got confused between what the prop is linked to. So if I summarize, we have:

  • onMonthChange that is correlated to the currently displayed month (the view). We could potentially have a defaultMonth and month prop if we wanted to increase user's control over this state. Ok, a great callback to have :).
  • onYearChange that is related to the currently selected date. Which is different from the state of the view that the previous callback represents.

I would propose that we remove onYearChange and replace it with a selectedDays/onSelectedDaysChange prop combination, that we also expose at the Calendar level, it would cover more use cases and clear the confusion. Something similar to http://react-day-picker.js.org/examples/selected-state.

This made me wonder, doesn't https://next.material-ui-pickers.dev/api/Calendar (the documentation) miss the prop to control the selected days (or range)?

oliviertassinari avatar Apr 13 '20 11:04 oliviertassinari

Already have. But not exposed to the user level. I am planning to make a new PR with an ability to select multiple dates.

dmtrKovalenko avatar Apr 13 '20 11:04 dmtrKovalenko

@oliviertassinari

onChange is only being called when we complete the wizard of selecting date+time (both) Now in the new version the Ok button is not available in the desktop mode So if the user just want to update the date, but not the time and clicks outside to dismiss the picker, there is no way to catch the updated date

That's why I was wondering something similar to an onDateChange callback will be really helpful in those scenarios

debojyoti avatar Apr 15 '20 18:04 debojyoti

@debojyoti Awesome, thanks for the feedback. A few thoughts, @dmtrKovalenko correct me if I'm wrong

  • onChange should be called when the user has confirmed the selection of the value. Depending on the props provided, it can happen when a day is clicked on or when the "OK" button is clicked.
  • onMonthChange should be called when the displayed month changes, not when the month of the selected date change.
  • onYearChange should be replaced with a onSelectedDayChange to cover more use cases (like the one here, and remove confusion).
  • In the case of the date-time picker, the "OK" button should always be visible as the only way to confirm a date.

Benchmark

  • https://ant.design/components/date-picker/#header
  • https://www.telerik.com/kendo-react-ui/components/dateinputs/datetimepicker/
  • https://ej2.syncfusion.com/react/demos/#/material/datetimepicker/default

oliviertassinari avatar Apr 15 '20 19:04 oliviertassinari