defaultDate prop in MonthPickerInput and YearPickerInput is ignored (tested fix enclosed) #7108
Closed
1 of 2 tasks
Labels
Fixed patch
Completed issues that will be published with next patch (1.0.X)
Dependencies check up
What version of @mantine/* packages do you have in package.json?
7.13.2
What package has an issue?
@mantine/dates
What framework do you use?
Next.js
In which browsers you can reproduce the issue?
None
Describe the bug
Both MonthPickerInput and YearPickerInput have the
getDefaultClampedDate
function called when setting thedefaultDate
if_value
or_value[0]
isnull
. When using these pickers in forms, where Mantine docs suggest using uncontrolled components for best performance of forms, thedefaultDate
prop becomes important. ThegetDefaultClampedDate
function doesn't resolve how I would expect it to though because it derives thedefaultDate
from theminDate
andmaxDate
props instead of using the developer-supplieddefaultDate
:mantine/packages/@mantine/dates/src/components/MonthPickerInput/MonthPickerInput.tsx
Lines 138 to 142 in 1d07a31
mantine/packages/@mantine/dates/src/components/YearPickerInput/YearPickerInput.tsx
Lines 133 to 138 in 1d07a31
mantine/packages/@mantine/dates/src/utils/get-default-clamped-date.ts
Lines 10 to 26 in 1d07a31
I think the MonthPickerInput and the YearPickerInput should operate the same way as the DatePickerInput when setting the
defaultDate
, otherwise thedefaultDate
prop on Month/Year pickers serves no purpose since it will always be derived from theminDate
ormaxDate
props.mantine/packages/@mantine/dates/src/components/DatePickerInput/DatePickerInput.tsx
Line 108 in 1d07a31
If possible, include a link to a codesandbox with a minimal reproduction
https://codesandbox.io/p/sandbox/mantine-react-template-forked-zxhyqr
Possible fix
I tested changing the code in the MonthPickerInput to this and it performed as I expected it to:
I tested changing the code in the YearPickerInput to the same code above and it performed as I expected it to also.
Self-service
The text was updated successfully, but these errors were encountered: