-
-
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] Use context to pass props from the picker to the field #16042
base: master
Are you sure you want to change the base?
[pickers] Use context to pass props from the picker to the field #16042
Conversation
…avior from the picker
Deploy preview: https://deploy-preview-16042--material-ui-x.netlify.app/ Updated pages: |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
* @param {string} params.format Format of the date to use. | ||
* @param {'dense' | 'spacious'} params.formatDensity Density of the format (setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character). | ||
* @param {boolean} params.shouldRespectLeadingZeros If `true`, the format will respect the leading zeroes, if `false`, the format will always add leading zeroes. | ||
* @param {string} params.format Format to parse. |
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.
-
shouldRespectLeadingZeros
: I removed it because it was doing nothing since it's a placeholder and a placeholder never has leading zeros 🤦 . -
formatDensity
: I removed it, but for this one it's more subjective and I would like your opinion. I can take it from the context and allow an override like for the format. My reasoning behind the removal is that the density is a concept internal to the our field. If someone uses it in a custom field (let say a masked field), then he/she will have an inconsistency between the placeholder (which will have the spaces) and the value (which wont). So I think it's better to just let the user use a good oldformat.replace(/\//g, ' / ')
. -
format
: I made it optional, by default it's using the one of the picker (or a default date format when using a standalone field but it's probably not a realistic use case)
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.
On the formatDensity
I do agree ... its probably best to give the user the freedom to use whatever density he prefers and apply it to both. 👍🏼
packages/x-date-pickers/src/internals/components/PickerProvider.tsx
Outdated
Show resolved
Hide resolved
@@ -41,16 +40,18 @@ function ButtonDateTimeField(props: DateTimePickerFieldProps) { | |||
} = forwardedProps; | |||
|
|||
const pickerContext = usePickerContext(); | |||
|
|||
const parsedFormat = useParsedFormat(internalProps); | |||
const parsedFormat = useParsedFormat(); | |||
const { hasValidationError } = useValidation({ |
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.
We would now be able to make value
and timezone
optional and read it from the context by default. Same with the validation props in the future.
But I would like to take the time to think this API correctly before doing anything.
docs/data/date-pickers/custom-field/behavior-autocomplete/MaterialDatePicker.js
Show resolved
Hide resolved
docs/data/date-pickers/custom-field/behavior-button/MaterialDateRangePicker.tsx
Outdated
Show resolved
Hide resolved
docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
Outdated
Show resolved
Hide resolved
docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
Outdated
Show resolved
Hide resolved
docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
Outdated
Show resolved
Hide resolved
docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
Outdated
Show resolved
Hide resolved
* @param {string} params.format Format of the date to use. | ||
* @param {'dense' | 'spacious'} params.formatDensity Density of the format (setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character). | ||
* @param {boolean} params.shouldRespectLeadingZeros If `true`, the format will respect the leading zeroes, if `false`, the format will always add leading zeroes. | ||
* @param {string} params.format Format to parse. |
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.
On the formatDensity
I do agree ... its probably best to give the user the freedom to use whatever density he prefers and apply it to both. 👍🏼
packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.types.ts
Outdated
Show resolved
Hide resolved
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
docs/data/date-pickers/custom-field/behavior-read-only-text-field/MaterialDatePicker.js
Show resolved
Hide resolved
docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
Outdated
Show resolved
Hide resolved
docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
Outdated
Show resolved
Hide resolved
- `onSelectedSectionsChange`: `undefined` | ||
|
||
:::success | ||
If you are using a hook like `useDateField`, you don't have to do anything, the value from the context are automatically applied. |
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.
If you are using a hook like `useDateField`, you don't have to do anything, the value from the context are automatically applied. | |
If you are using a hook, like `useDateField`, you don't have to do anything, the values from the context are automatically applied. |
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 might have applied the comment before too fast.
It's not all hooks, only some of them.
For me If your are using a hook, like
useDateField, you ...
implies that the condition if "If you are using a hook", which is not accurate here.
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.
Oh, sorry for misleading you. 🙈
packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.tsx
Show resolved
Hide resolved
packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.types.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Lukas Tyla <[email protected]> Signed-off-by: Flavien DELANGLE <[email protected]>
Co-authored-by: Lukas Tyla <[email protected]> Signed-off-by: Flavien DELANGLE <[email protected]>
Part of #16059
This PR only cover the props that are common to all the fields, otherwise it would be too big and hard to review.
For now the validation props and some other prop are still passed to the field using props (see "Follow up" for more details).
disabled
,value
andsetValue
from the existing public context in the field componentsfieldFormat
andtimezone
to the existing public context and use them in the field componentsformatDensity
andshouldRespectLeadingZeros
fromuseParsedFormat
, and makeformat
optional (use the one passed by the picker by default).Follow up
readOnly
andautoFocus
(requires [pickers] Let the field components handle their opening UI, and allow field editing on mobile pickers #15671)inputRef
,unstableFieldRef
,name
andlabel
(need to make single input range fields the default before)ref
(currently handed by each picker individually)