In the date picker documentation, it requires onChange handler, and has optional onYearChange and onMonthChange handlers but does not have an onDayChange handler. Is there a way to only trigger a date change when only the day changes?
I've tried storing the old date and comparing to the new one onChange to see if the day changed, but changing the year and/or month adjusts the date as well since it triggers onChange.
import React, { useState } from 'react';
import TextField from '@mui/material/TextField';
import AdapterDateFns from '@mui/lab/AdapterDateFns';
import LocalizationProvider from '@mui/lab/LocalizationProvider';
import DatePicker from '@mui/lab/DatePicker';
function DatePickerComponent() {
const defaultMinDate = new Date('1900-01-01T17:00:00');
const [value, setValue] = useState(new Date());
return (
<LocalizationProvider dateAdapter={AdapterDateFns}>
<DatePicker
label="Filter By Date (start)"
openTo="year"
views={['year', 'month', 'day']}
minDate={defaultMinDate}
value={value}
onChange={(newValue) => {
setValue(newValue);
}}
renderInput={(params) => <TextField {...params} variant="standard" />}
/>
</LocalizationProvider>
);
}
export default DatePickerComponent;