[DateTimePicker] Always show the "OK" button
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 I don't understand, what's wrong with the usage of an
onChangeprop only? - @dmtrKovalenko I don't understand the motivation for the existence of the
onMonthChangeandonYearChangeprop. Would it be possible to remove these props?
@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 Right, I got confused between what the prop is linked to. So if I summarize, we have:
onMonthChangethat is correlated to the currently displayed month (the view). We could potentially have adefaultMonthandmonthprop if we wanted to increase user's control over this state. Ok, a great callback to have :).onYearChangethat 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)?
Already have. But not exposed to the user level. I am planning to make a new PR with an ability to select multiple dates.
@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 Awesome, thanks for the feedback. A few thoughts, @dmtrKovalenko correct me if I'm wrong
onChangeshould 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.onMonthChangeshould be called when the displayed month changes, not when the month of the selected date change.onYearChangeshould be replaced with aonSelectedDayChangeto 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