Skip to content
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] Limit the valid values of TDate #11791

Merged
merged 24 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function GridEditDateCell({
field,
value,
colDef,
}: GridRenderEditCellParams<any, Date | string | null>) {
}: GridRenderEditCellParams<any, Date | null, string>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a fix of something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the date in the pickers can no longer be a string since v6 and the formatted value on the other hand is always a string

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Letting @mui/xgrid know.
Maybe you need to add a mention of this fact somewhere as well as it could impact the users. 🤔
Clarifying that this is technically not BC, because it is already the case for v6. 🙈 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this looks good to me 👍🏻

const apiRef = useGridApiContext();

const Component = colDef.type === 'dateTime' ? DateTimePicker : DatePicker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
SingleInputDateRangeFieldProps,
} from '@mui/x-date-pickers-pro/SingleInputDateRangeField';
import { DemoContainer } from '@mui/x-date-pickers/internals/demo';
import { PickerValidDate } from '@mui/x-date-pickers/models';

type FieldComponent = (<TDate>(
type FieldComponent = (<TDate extends PickerValidDate>(
props: SingleInputDateRangeFieldProps<TDate> &
React.RefAttributes<HTMLInputElement>,
) => React.JSX.Element) & { fieldType?: string };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function LifeCycleDateFieldEmpty() {
return (
<Stack spacing={2}>
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DateField value={value} onChange={(newValue) => setValue(newValue)} />
<DateField value={value} onChange={setValue} />
</LocalizationProvider>
<Typography>Value: {value == null ? 'null' : value.format('L')}</Typography>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function LifeCycleDateFieldEmpty() {
return (
<Stack spacing={2}>
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DateField value={value} onChange={(newValue) => setValue(newValue)} />
<DateField value={value} onChange={setValue} />
</LocalizationProvider>
<Typography>Value: {value == null ? 'null' : value.format('L')}</Typography>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DateField value={value} onChange={(newValue) => setValue(newValue)} />
<DateField value={value} onChange={setValue} />
</LocalizationProvider>
<Typography>Value: {value == null ? 'null' : value.format('L')}</Typography>
5 changes: 1 addition & 4 deletions docs/data/date-pickers/lifecycle/LifeCycleDateRangeField.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ export default function LifeCycleDateRangeField() {
<Stack spacing={2}>
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['SingleInputDateRangeField']}>
<SingleInputDateRangeField
value={value}
onChange={(newValue) => setValue(newValue)}
/>
<SingleInputDateRangeField value={value} onChange={setValue} />
</DemoContainer>
</LocalizationProvider>
<Typography>
Expand Down
7 changes: 2 additions & 5 deletions docs/data/date-pickers/lifecycle/LifeCycleDateRangeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SingleInputDateRangeField } from '@mui/x-date-pickers-pro/SingleInputDa
import { DateRange } from '@mui/x-date-pickers-pro/models';

export default function LifeCycleDateRangeField() {
const [value, setValue] = React.useState<DateRange<Dayjs | null>>([
const [value, setValue] = React.useState<DateRange<Dayjs>>([
dayjs('2022-04-17'),
null,
]);
Expand All @@ -18,10 +18,7 @@ export default function LifeCycleDateRangeField() {
<Stack spacing={2}>
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['SingleInputDateRangeField']}>
<SingleInputDateRangeField
value={value}
onChange={(newValue) => setValue(newValue)}
/>
<SingleInputDateRangeField value={value} onChange={setValue} />
</DemoContainer>
</LocalizationProvider>
<Typography>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['SingleInputDateRangeField']}>
<SingleInputDateRangeField
value={value}
onChange={(newValue) => setValue(newValue)}
/>
<SingleInputDateRangeField value={value} onChange={setValue} />
</DemoContainer>
</LocalizationProvider>
<Typography>
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/x/api/date-pickers/date-calendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"returned": "string"
}
},
"defaultValue": { "type": { "name": "any" } },
"defaultValue": { "type": { "name": "object" } },
"disabled": { "type": { "name": "bool" }, "default": "false" },
"disableFuture": { "type": { "name": "bool" }, "default": "false" },
"disableHighlightToday": { "type": { "name": "bool" }, "default": "false" },
Expand All @@ -24,8 +24,8 @@
}
},
"loading": { "type": { "name": "bool" }, "default": "false" },
"maxDate": { "type": { "name": "any" } },
"minDate": { "type": { "name": "any" } },
"maxDate": { "type": { "name": "object" } },
"minDate": { "type": { "name": "object" } },
"monthsPerRow": {
"type": { "name": "enum", "description": "3<br>&#124;&nbsp;4" },
"default": "3"
Expand Down Expand Up @@ -68,7 +68,7 @@
"default": "`@media(prefers-reduced-motion: reduce)` || `navigator.userAgent` matches Android <10 or iOS <13"
},
"referenceDate": {
"type": { "name": "any" },
"type": { "name": "object" },
"default": "The closest valid date using the validation props, except callbacks such as `shouldDisableDate`."
},
"renderLoading": {
Expand Down Expand Up @@ -126,7 +126,7 @@
"text": "timezones documentation"
}
},
"value": { "type": { "name": "any" } },
"value": { "type": { "name": "object" } },
"view": {
"type": {
"name": "enum",
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/x/api/date-pickers/date-field.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"default": "'primary'"
},
"defaultValue": { "type": { "name": "any" } },
"defaultValue": { "type": { "name": "object" } },
"disabled": { "type": { "name": "bool" }, "default": "false" },
"disableFuture": { "type": { "name": "bool" }, "default": "false" },
"disablePast": { "type": { "name": "bool" }, "default": "false" },
Expand All @@ -36,8 +36,8 @@
},
"default": "'none'"
},
"maxDate": { "type": { "name": "any" } },
"minDate": { "type": { "name": "any" } },
"maxDate": { "type": { "name": "object" } },
"minDate": { "type": { "name": "object" } },
"name": { "type": { "name": "string" } },
"onChange": {
"type": { "name": "func" },
Expand All @@ -63,7 +63,7 @@
},
"readOnly": { "type": { "name": "bool" }, "default": "false" },
"referenceDate": {
"type": { "name": "any" },
"type": { "name": "object" },
"default": "The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used."
},
"required": { "type": { "name": "bool" }, "default": "false" },
Expand Down Expand Up @@ -123,7 +123,7 @@
"unstableFieldRef": {
"type": { "name": "union", "description": "func<br>&#124;&nbsp;object" }
},
"value": { "type": { "name": "any" } },
"value": { "type": { "name": "object" } },
"variant": {
"type": {
"name": "enum",
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/x/api/date-pickers/date-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"returned": "string"
}
},
"defaultValue": { "type": { "name": "any" } },
"defaultValue": { "type": { "name": "object" } },
"desktopModeMediaQuery": {
"type": { "name": "string" },
"default": "'@media (pointer: fine)'"
Expand All @@ -35,8 +35,8 @@
"label": { "type": { "name": "node" } },
"loading": { "type": { "name": "bool" }, "default": "false" },
"localeText": { "type": { "name": "object" } },
"maxDate": { "type": { "name": "any" } },
"minDate": { "type": { "name": "any" } },
"maxDate": { "type": { "name": "object" } },
"minDate": { "type": { "name": "object" } },
"monthsPerRow": {
"type": { "name": "enum", "description": "3<br>&#124;&nbsp;4" },
"default": "3"
Expand Down Expand Up @@ -96,7 +96,7 @@
"default": "`@media(prefers-reduced-motion: reduce)` || `navigator.userAgent` matches Android <10 or iOS <13"
},
"referenceDate": {
"type": { "name": "any" },
"type": { "name": "object" },
"default": "The closest valid date-time using the validation props, except callbacks like `shouldDisable<...>`."
},
"renderLoading": {
Expand Down Expand Up @@ -160,7 +160,7 @@
"text": "timezones documentation"
}
},
"value": { "type": { "name": "any" } },
"value": { "type": { "name": "object" } },
"view": {
"type": {
"name": "enum",
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/x/api/date-pickers/date-range-calendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"type": { "name": "enum", "description": "'end'<br>&#124;&nbsp;'start'" },
"default": "'start'"
},
"defaultValue": { "type": { "name": "arrayOf", "description": "Array&lt;any&gt;" } },
"defaultValue": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAutoMonthSwitching": { "type": { "name": "bool" }, "default": "false" },
"disabled": { "type": { "name": "bool" }, "default": "false" },
"disableDragEditing": { "type": { "name": "bool" }, "default": "false" },
Expand All @@ -37,8 +37,8 @@
"fixedWeekNumber": { "type": { "name": "number" }, "default": "undefined" },
"focusedView": { "type": { "name": "enum", "description": "'day'" } },
"loading": { "type": { "name": "bool" }, "default": "false" },
"maxDate": { "type": { "name": "any" } },
"minDate": { "type": { "name": "any" } },
"maxDate": { "type": { "name": "object" } },
"minDate": { "type": { "name": "object" } },
"onChange": {
"type": { "name": "func" },
"signature": {
Expand Down Expand Up @@ -76,7 +76,7 @@
"default": "`@media(prefers-reduced-motion: reduce)` || `navigator.userAgent` matches Android <10 or iOS <13"
},
"referenceDate": {
"type": { "name": "any" },
"type": { "name": "object" },
"default": "The closest valid date using the validation props, except callbacks such as `shouldDisableDate`."
},
"renderLoading": {
Expand Down Expand Up @@ -118,7 +118,7 @@
"text": "timezones documentation"
}
},
"value": { "type": { "name": "arrayOf", "description": "Array&lt;any&gt;" } },
"value": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"view": { "type": { "name": "enum", "description": "'day'" } },
"views": { "type": { "name": "arrayOf", "description": "Array&lt;'day'&gt;" } }
},
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/date-range-picker-day.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"props": {
"day": { "type": { "name": "any" }, "required": true },
"day": { "type": { "name": "object" }, "required": true },
"isEndOfHighlighting": { "type": { "name": "bool" }, "required": true },
"isEndOfPreviewing": { "type": { "name": "bool" }, "required": true },
"isFirstVisibleCell": { "type": { "name": "bool" }, "required": true },
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/x/api/date-pickers/date-range-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"type": { "name": "enum", "description": "'end'<br>&#124;&nbsp;'start'" },
"default": "'start'"
},
"defaultValue": { "type": { "name": "arrayOf", "description": "Array&lt;any&gt;" } },
"defaultValue": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"desktopModeMediaQuery": {
"type": { "name": "string" },
"default": "'@media (pointer: fine)'"
Expand All @@ -49,8 +49,8 @@
"label": { "type": { "name": "node" } },
"loading": { "type": { "name": "bool" }, "default": "false" },
"localeText": { "type": { "name": "object" } },
"maxDate": { "type": { "name": "any" } },
"minDate": { "type": { "name": "any" } },
"maxDate": { "type": { "name": "object" } },
"minDate": { "type": { "name": "object" } },
"name": { "type": { "name": "string" } },
"onAccept": {
"type": { "name": "func" },
Expand Down Expand Up @@ -97,7 +97,7 @@
"default": "`@media(prefers-reduced-motion: reduce)` || `navigator.userAgent` matches Android <10 or iOS <13"
},
"referenceDate": {
"type": { "name": "any" },
"type": { "name": "object" },
"default": "The closest valid date-time using the validation props, except callbacks like `shouldDisable<...>`."
},
"renderLoading": {
Expand Down Expand Up @@ -145,7 +145,7 @@
"text": "timezones documentation"
}
},
"value": { "type": { "name": "arrayOf", "description": "Array&lt;any&gt;" } },
"value": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"viewRenderers": { "type": { "name": "shape", "description": "{ day?: func }" } }
},
"name": "DateRangePicker",
Expand Down
18 changes: 9 additions & 9 deletions docs/pages/x/api/date-pickers/date-time-field.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"default": "'primary'"
},
"defaultValue": { "type": { "name": "any" } },
"defaultValue": { "type": { "name": "object" } },
"disabled": { "type": { "name": "bool" }, "default": "false" },
"disableFuture": { "type": { "name": "bool" }, "default": "false" },
"disableIgnoringDatePartForTimeValidation": { "type": { "name": "bool" }, "default": "false" },
Expand Down Expand Up @@ -38,12 +38,12 @@
},
"default": "'none'"
},
"maxDate": { "type": { "name": "any" } },
"maxDateTime": { "type": { "name": "any" } },
"maxTime": { "type": { "name": "any" } },
"minDate": { "type": { "name": "any" } },
"minDateTime": { "type": { "name": "any" } },
"minTime": { "type": { "name": "any" } },
"maxDate": { "type": { "name": "object" } },
"maxDateTime": { "type": { "name": "object" } },
"maxTime": { "type": { "name": "object" } },
"minDate": { "type": { "name": "object" } },
"minDateTime": { "type": { "name": "object" } },
"minTime": { "type": { "name": "object" } },
"minutesStep": { "type": { "name": "number" }, "default": "1" },
"name": { "type": { "name": "string" } },
"onChange": {
Expand All @@ -70,7 +70,7 @@
},
"readOnly": { "type": { "name": "bool" }, "default": "false" },
"referenceDate": {
"type": { "name": "any" },
"type": { "name": "object" },
"default": "The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used."
},
"required": { "type": { "name": "bool" }, "default": "false" },
Expand Down Expand Up @@ -138,7 +138,7 @@
"unstableFieldRef": {
"type": { "name": "union", "description": "func<br>&#124;&nbsp;object" }
},
"value": { "type": { "name": "any" } },
"value": { "type": { "name": "object" } },
"variant": {
"type": {
"name": "enum",
Expand Down
18 changes: 9 additions & 9 deletions docs/pages/x/api/date-pickers/date-time-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"returned": "string"
}
},
"defaultValue": { "type": { "name": "any" } },
"defaultValue": { "type": { "name": "object" } },
"desktopModeMediaQuery": {
"type": { "name": "string" },
"default": "'@media (pointer: fine)'"
Expand All @@ -38,12 +38,12 @@
"label": { "type": { "name": "node" } },
"loading": { "type": { "name": "bool" }, "default": "false" },
"localeText": { "type": { "name": "object" } },
"maxDate": { "type": { "name": "any" } },
"maxDateTime": { "type": { "name": "any" } },
"maxTime": { "type": { "name": "any" } },
"minDate": { "type": { "name": "any" } },
"minDateTime": { "type": { "name": "any" } },
"minTime": { "type": { "name": "any" } },
"maxDate": { "type": { "name": "object" } },
"maxDateTime": { "type": { "name": "object" } },
"maxTime": { "type": { "name": "object" } },
"minDate": { "type": { "name": "object" } },
"minDateTime": { "type": { "name": "object" } },
"minTime": { "type": { "name": "object" } },
"minutesStep": { "type": { "name": "number" }, "default": "1" },
"monthsPerRow": {
"type": { "name": "enum", "description": "3<br>&#124;&nbsp;4" },
Expand Down Expand Up @@ -104,7 +104,7 @@
"default": "`@media(prefers-reduced-motion: reduce)` || `navigator.userAgent` matches Android <10 or iOS <13"
},
"referenceDate": {
"type": { "name": "any" },
"type": { "name": "object" },
"default": "The closest valid date-time using the validation props, except callbacks like `shouldDisable<...>`."
},
"renderLoading": {
Expand Down Expand Up @@ -185,7 +185,7 @@
"text": "timezones documentation"
}
},
"value": { "type": { "name": "any" } },
"value": { "type": { "name": "object" } },
"view": {
"type": {
"name": "enum",
Expand Down
Loading
Loading