-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pickers] Strictly type the props a picker passes to its field, and migrate all the custom field demos accordingly #15197
[pickers] Strictly type the props a picker passes to its field, and migrate all the custom field demos accordingly #15197
Conversation
19ee412
to
6410aaf
Compare
@@ -4,18 +4,14 @@ import useForkRef from '@mui/utils/useForkRef'; | |||
import { styled } from '@mui/material/styles'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use
DatePickerFieldProps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks immensely cleaner. 😱 💯
@@ -8,18 +8,15 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | |||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use
DateRangePickerFieldProps
(with a small adaptation to work with multi input range field, I can create aDateRangePickerMultiInputFieldProps
if you want that in the lib, my assumption that since we migrate away from multi input, it's not needed). - Replace
BasePickersTextFieldProps
withBaseMultiInputPickersTextFieldProps
(BaseMultiInputPickersTextFieldProps
andBaseSingleInputPickersTextFieldProps
are now incompatible soBasePickersTextFieldProps
can't exist, and since we are migrating away from multi input I think we don't have to support this abstraction) - Remove
defaultValue
andonError
props which are never passed by the picker to the field so a field built to be used inside a picker doesn't have to support them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the assumptions and the resulting compromises. 👍
@@ -10,22 +10,14 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | |||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use
DateRangePickerFieldProps
- Replace
BasePickersTextFieldProps
withBaseSingleInputPickersTextFieldProps
(BaseMultiInputPickersTextFieldProps
andBaseSingleInputPickersTextFieldProps
are now incompatible soBasePickersTextFieldProps
can't exist, and since we are migrating away from multi input I think we don't have to support this abstraction) - Use
usePickersContext
to open the picker instead of passing a custom prop usingslotProps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look epic and way cleaner without the need to control nested slotProps. 🎉
@@ -16,17 +16,13 @@ import FormControl from '@mui/joy/FormControl'; | |||
import FormLabel from '@mui/joy/FormLabel'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use
DatePickerFieldProps
@@ -22,16 +22,13 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | |||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use
DateRangePickerFieldProps
(with a small adaptation to work with multi input range field, I can create aDateRangePickerMultiInputFieldProps
if you want that in the lib, my assumption that since we migrate away from multi input, it's not needed). - Remove
defaultValue
andonError
props which are never passed by the picker to the field so a field built to be used inside a picker doesn't have to support them - Add support for
unstableStartFieldRef
/unstableEndFieldRef
@@ -21,20 +21,12 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | |||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use
DateRangePickerFieldProps
- Use
usePickersContext
to open the picker instead of passing a custom prop usingslotProps
@@ -36,7 +36,7 @@ function AutocompleteField(props: AutocompleteFieldProps) { | |||
...other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add the validation error in the
onChange
context - Don't check if
onChange
exists since it always does when used inside a picker
@@ -2,7 +2,6 @@ import * as React from 'react'; | |||
import dayjs, { Dayjs } from 'dayjs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Unify the wording by removing
ValueStr
everywhere in favor ofInputValue
- Don't check if
onChange
exists since it always does when used inside a picker - Remove
defaultValue
prop and assumevalue
is always defined (which is the case when the field is used inside a picker)
6410aaf
to
59c8cd5
Compare
@@ -3,67 +3,67 @@ import dayjs, { Dayjs } from 'dayjs'; | |||
import Button from '@mui/material/Button'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use
DatePickerFieldProps
- Use
useParsedFormat
to generate the label of theButton
instead of setting the format in thelabel
of the picker (the end result is the same) - Use
usePickersContext
to open the picker - Use
useSplitFieldProps
to be able to forward the props to the DOM - Use
useValidation
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
7593495
to
2b77887
Compare
2b77887
to
33bdaff
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
- If you are building a custom field for a Date Picker: | ||
|
||
```diff | ||
-import { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code is always with the old generic (TDate
, TValue
and TSection
), not the new version of BaseSingleInputFieldProps
that people can't use anymore anyway).
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Epic work and result of type simplification. 👏
Leaving some questions and nitpicks. 😉 🙈
P.S. WDYT about changing the PR title prefix to [pickers]
?
It's slightly change to deliver a BC within a [docs]
PR. 🙈 😆
@@ -4,18 +4,14 @@ import useForkRef from '@mui/utils/useForkRef'; | |||
import { styled } from '@mui/material/styles'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks immensely cleaner. 😱 💯
@@ -8,18 +8,15 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | |||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the assumptions and the resulting compromises. 👍
@@ -10,22 +10,14 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | |||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look epic and way cleaner without the need to control nested slotProps. 🎉
docs/data/date-pickers/custom-field/BrowserV7SingleInputRangeField.tsx
Outdated
Show resolved
Hide resolved
docs/data/date-pickers/custom-field/JoyV6SingleInputRangeField.tsx
Outdated
Show resolved
Hide resolved
packages/x-date-pickers/src/internals/hooks/useDesktopPicker/useDesktopPicker.tsx
Outdated
Show resolved
Hide resolved
@@ -4,10 +4,7 @@ | |||
{ "name": "ArrowDropDownIcon", "kind": "Variable" }, | |||
{ "name": "ArrowLeftIcon", "kind": "Variable" }, | |||
{ "name": "ArrowRightIcon", "kind": "Variable" }, | |||
{ "name": "BaseMultiInputFieldProps", "kind": "Interface" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we list these in the changelog of the PR as well? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I'm waiting for the alpha 0 to be released to have a clearer vision of how we want to phrase those changes but I'll add them in the PR description 👍
You are entirely right 😬 |
bd54062
to
06f7bbc
Compare
06f7bbc
to
94e2bef
Compare
9b5af2f
to
454f8d5
Compare
454f8d5
to
e040f2e
Compare
Extracted from #15194
Part of #14496
I wasn't able to split this one in smaller pieces because updating the demos without updating the package results in TS issues and vice-versa 😢 .
I tried to be as detailed as possible in my comments / description to help the review.
In this PR
BaseSingleInputFieldProps
andBaseMultiInputFieldProps
to typeslotProps.field
(the JSDoc said to not use it for this purpose even before this PR 😬 ) and stop exporting them (they are now only used to create interfaces likeDatePickerFieldProps
).BaseSingleInputFieldProps
andBaseMultiInputFieldProps
to accurately match what the picker are passing, which one are nullable and which one have a default value applied.PickersFieldSlotProps
andPickersRangeFieldSlotProps
interfaces to describe whatslotProps.field
can receive. Those props are very limited for now to only contain stuff people should actually pass (I did not add any props that are forwarded by the picker, likeformat
to avoid having several way to achieve the same outcome. If you have some props that you think are missing please let me know).ValidateXXXProps
interfaces in the interfaces likeDatePickerFieldProps
instead ofUseDateFieldProps
(this makesDatePickerFieldProps
a lot more accurate, without props likedefaultValue
that are never defined).useSlotProps
of theuseXXXPicker
hooks) to accurately match what the new typing expects.custom-field
page to match the new typing (I did a comment per demo to describe the changes, for the Joy UI I didn't try to migrate more than what was necessary since they are going away in the future).Follow up