@mui/x-date-pickers 7.7.0 → 7.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/AdapterDateFns/AdapterDateFns.d.ts +0 -1
  2. package/AdapterDateFnsJalali/AdapterDateFnsJalali.d.ts +0 -1
  3. package/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.d.ts +48 -48
  4. package/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +1 -0
  5. package/AdapterDateFnsV3/AdapterDateFnsV3.d.ts +47 -47
  6. package/AdapterDateFnsV3/AdapterDateFnsV3.js +1 -0
  7. package/CHANGELOG.md +181 -0
  8. package/DateCalendar/useCalendarState.d.ts +1 -1
  9. package/DatePicker/DatePicker.js +2 -0
  10. package/DateTimePicker/DateTimePicker.js +2 -0
  11. package/DateTimePicker/DateTimePickerToolbar.js +1 -1
  12. package/DesktopDatePicker/DesktopDatePicker.js +2 -0
  13. package/DesktopDateTimePicker/DesktopDateTimePicker.js +5 -1
  14. package/DesktopDateTimePicker/DesktopDateTimePickerLayout.d.ts +1 -1
  15. package/DesktopTimePicker/DesktopTimePicker.js +2 -0
  16. package/MobileDatePicker/MobileDatePicker.js +2 -0
  17. package/MobileDateTimePicker/MobileDateTimePicker.js +2 -0
  18. package/MobileTimePicker/MobileTimePicker.js +2 -0
  19. package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +16 -3
  20. package/PickersCalendarHeader/PickersCalendarHeader.js +4 -0
  21. package/PickersCalendarHeader/PickersCalendarHeader.types.d.ts +4 -0
  22. package/PickersLayout/usePickerLayout.js +0 -5
  23. package/StaticDatePicker/StaticDatePicker.js +2 -0
  24. package/StaticDateTimePicker/StaticDateTimePicker.js +2 -0
  25. package/StaticTimePicker/StaticTimePicker.js +2 -0
  26. package/TimeClock/ClockNumbers.d.ts +1 -1
  27. package/TimePicker/TimePicker.js +2 -0
  28. package/index.js +1 -1
  29. package/internals/components/PickerViewRoot/PickerViewRoot.d.ts +0 -1
  30. package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +4 -2
  31. package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.types.d.ts +1 -0
  32. package/internals/hooks/date-helpers-hooks.d.ts +1 -1
  33. package/internals/hooks/defaultizedFieldProps.d.ts +2 -2
  34. package/internals/hooks/useField/useField.d.ts +3 -3
  35. package/internals/hooks/useField/useField.utils.d.ts +3 -3
  36. package/internals/hooks/useField/useField.utils.js +2 -1
  37. package/internals/hooks/useField/useFieldV6TextField.js +9 -3
  38. package/internals/hooks/usePicker/usePickerValue.js +45 -38
  39. package/internals/hooks/usePicker/usePickerValue.types.d.ts +3 -2
  40. package/internals/hooks/usePicker/usePickerViews.js +2 -1
  41. package/internals/utils/date-utils.d.ts +1 -1
  42. package/internals/utils/views.d.ts +1 -1
  43. package/internals/utils/warning.d.ts +1 -1
  44. package/locales/daDK.js +15 -19
  45. package/modern/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +1 -0
  46. package/modern/AdapterDateFnsV3/AdapterDateFnsV3.js +1 -0
  47. package/modern/DatePicker/DatePicker.js +2 -0
  48. package/modern/DateTimePicker/DateTimePicker.js +2 -0
  49. package/modern/DateTimePicker/DateTimePickerToolbar.js +1 -1
  50. package/modern/DesktopDatePicker/DesktopDatePicker.js +2 -0
  51. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +5 -1
  52. package/modern/DesktopTimePicker/DesktopTimePicker.js +2 -0
  53. package/modern/MobileDatePicker/MobileDatePicker.js +2 -0
  54. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +2 -0
  55. package/modern/MobileTimePicker/MobileTimePicker.js +2 -0
  56. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +16 -3
  57. package/modern/PickersCalendarHeader/PickersCalendarHeader.js +4 -0
  58. package/modern/PickersLayout/usePickerLayout.js +0 -5
  59. package/modern/StaticDatePicker/StaticDatePicker.js +2 -0
  60. package/modern/StaticDateTimePicker/StaticDateTimePicker.js +2 -0
  61. package/modern/StaticTimePicker/StaticTimePicker.js +2 -0
  62. package/modern/TimePicker/TimePicker.js +2 -0
  63. package/modern/index.js +1 -1
  64. package/modern/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +4 -2
  65. package/modern/internals/hooks/useField/useField.utils.js +2 -1
  66. package/modern/internals/hooks/useField/useFieldV6TextField.js +9 -3
  67. package/modern/internals/hooks/usePicker/usePickerValue.js +45 -38
  68. package/modern/internals/hooks/usePicker/usePickerViews.js +2 -1
  69. package/modern/locales/daDK.js +15 -19
  70. package/node/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +1 -0
  71. package/node/AdapterDateFnsV3/AdapterDateFnsV3.js +1 -0
  72. package/node/DatePicker/DatePicker.js +2 -0
  73. package/node/DateTimePicker/DateTimePicker.js +2 -0
  74. package/node/DateTimePicker/DateTimePickerToolbar.js +2 -2
  75. package/node/DesktopDatePicker/DesktopDatePicker.js +2 -0
  76. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +12 -8
  77. package/node/DesktopTimePicker/DesktopTimePicker.js +2 -0
  78. package/node/MobileDatePicker/MobileDatePicker.js +2 -0
  79. package/node/MobileDateTimePicker/MobileDateTimePicker.js +2 -0
  80. package/node/MobileTimePicker/MobileTimePicker.js +2 -0
  81. package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +16 -3
  82. package/node/PickersCalendarHeader/PickersCalendarHeader.js +4 -0
  83. package/node/PickersLayout/usePickerLayout.js +0 -5
  84. package/node/StaticDatePicker/StaticDatePicker.js +2 -0
  85. package/node/StaticDateTimePicker/StaticDateTimePicker.js +2 -0
  86. package/node/StaticTimePicker/StaticTimePicker.js +2 -0
  87. package/node/TimePicker/TimePicker.js +2 -0
  88. package/node/index.js +1 -1
  89. package/node/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +4 -2
  90. package/node/internals/hooks/useField/useField.utils.js +2 -1
  91. package/node/internals/hooks/useField/useFieldV6TextField.js +9 -3
  92. package/node/internals/hooks/usePicker/usePickerValue.js +45 -38
  93. package/node/internals/hooks/usePicker/usePickerViews.js +2 -1
  94. package/node/locales/daDK.js +15 -19
  95. package/package.json +3 -3
  96. package/timeViewRenderers/timeViewRenderers.d.ts +1 -1
@@ -53,7 +53,6 @@ const usePickerLayout = props => {
53
53
  const classes = useUtilityClasses(props);
54
54
 
55
55
  // Action bar
56
-
57
56
  const ActionBar = slots?.actionBar ?? PickersActionBar;
58
57
  const actionBarProps = useSlotProps({
59
58
  elementType: ActionBar,
@@ -73,7 +72,6 @@ const usePickerLayout = props => {
73
72
  const actionBar = /*#__PURE__*/_jsx(ActionBar, _extends({}, actionBarProps));
74
73
 
75
74
  // Toolbar
76
-
77
75
  const Toolbar = slots?.toolbar;
78
76
  const toolbarProps = useSlotProps({
79
77
  elementType: Toolbar,
@@ -96,11 +94,9 @@ const usePickerLayout = props => {
96
94
  const toolbar = toolbarHasView(toolbarProps) && !!Toolbar ? /*#__PURE__*/_jsx(Toolbar, _extends({}, toolbarProps)) : null;
97
95
 
98
96
  // Content
99
-
100
97
  const content = children;
101
98
 
102
99
  // Tabs
103
-
104
100
  const Tabs = slots?.tabs;
105
101
  const tabs = view && Tabs ? /*#__PURE__*/_jsx(Tabs, _extends({
106
102
  view: view,
@@ -109,7 +105,6 @@ const usePickerLayout = props => {
109
105
  }, slotProps?.tabs)) : null;
110
106
 
111
107
  // Shortcuts
112
-
113
108
  const Shortcuts = slots?.shortcuts ?? PickersShortcuts;
114
109
  const shortcutsProps = useSlotProps({
115
110
  elementType: Shortcuts,
@@ -133,7 +133,9 @@ StaticDatePicker.propTypes = {
133
133
  /**
134
134
  * Callback fired when the value is accepted.
135
135
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
136
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
136
137
  * @param {TValue} value The value that was just accepted.
138
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
137
139
  */
138
140
  onAccept: PropTypes.func,
139
141
  /**
@@ -181,7 +181,9 @@ StaticDateTimePicker.propTypes = {
181
181
  /**
182
182
  * Callback fired when the value is accepted.
183
183
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
184
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
184
185
  * @param {TValue} value The value that was just accepted.
186
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
185
187
  */
186
188
  onAccept: PropTypes.func,
187
189
  /**
@@ -125,7 +125,9 @@ StaticTimePicker.propTypes = {
125
125
  /**
126
126
  * Callback fired when the value is accepted.
127
127
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
128
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
128
129
  * @param {TValue} value The value that was just accepted.
130
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
129
131
  */
130
132
  onAccept: PropTypes.func,
131
133
  /**
@@ -18,7 +18,7 @@ interface GetHourNumbersOptions<TDate extends PickerValidDate> {
18
18
  * @ignore - internal component.
19
19
  */
20
20
  export declare const getHourNumbers: <TDate extends PickerValidDate>({ ampm, value, getClockNumberText, isDisabled, selectedId, utils, }: GetHourNumbersOptions<TDate>) => React.JSX.Element[];
21
- export declare const getMinutesNumbers: <TDate extends PickerValidDate>({ utils, value, isDisabled, getClockNumberText, selectedId, }: Omit<GetHourNumbersOptions<TDate>, 'ampm' | 'value'> & {
21
+ export declare const getMinutesNumbers: <TDate extends PickerValidDate>({ utils, value, isDisabled, getClockNumberText, selectedId, }: Omit<GetHourNumbersOptions<TDate>, "ampm" | "value"> & {
22
22
  value: number;
23
23
  }) => React.JSX.Element[];
24
24
  export {};
@@ -157,7 +157,9 @@ process.env.NODE_ENV !== "production" ? TimePicker.propTypes = {
157
157
  /**
158
158
  * Callback fired when the value is accepted.
159
159
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
160
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
160
161
  * @param {TValue} value The value that was just accepted.
162
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
161
163
  */
162
164
  onAccept: PropTypes.func,
163
165
  /**
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v7.7.0
2
+ * @mui/x-date-pickers v7.8.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
1
  export declare const PickerViewRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["children", "className", "slots", "slotProps", "isNextDisabled", "isNextHidden", "onGoToNext", "nextLabel", "isPreviousDisabled", "isPreviousHidden", "onGoToPrevious", "previousLabel"],
3
+ const _excluded = ["children", "className", "slots", "slotProps", "isNextDisabled", "isNextHidden", "onGoToNext", "nextLabel", "isPreviousDisabled", "isPreviousHidden", "onGoToPrevious", "previousLabel", "labelId"],
4
4
  _excluded2 = ["ownerState"],
5
5
  _excluded3 = ["ownerState"];
6
6
  import * as React from 'react';
@@ -73,7 +73,8 @@ export const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function Picke
73
73
  isPreviousDisabled,
74
74
  isPreviousHidden,
75
75
  onGoToPrevious,
76
- previousLabel
76
+ previousLabel,
77
+ labelId
77
78
  } = props,
78
79
  other = _objectWithoutPropertiesLoose(props, _excluded);
79
80
  const ownerState = props;
@@ -156,6 +157,7 @@ export const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function Picke
156
157
  })), children ? /*#__PURE__*/_jsx(Typography, {
157
158
  variant: "subtitle1",
158
159
  component: "span",
160
+ id: labelId,
159
161
  children: children
160
162
  }) : /*#__PURE__*/_jsx(PickersArrowSwitcherSpacer, {
161
163
  className: classes.spacer,
@@ -34,6 +34,7 @@ export interface PickersArrowSwitcherProps extends ExportedPickersArrowSwitcherP
34
34
  isNextHidden?: boolean;
35
35
  onGoToNext: () => void;
36
36
  nextLabel: string;
37
+ labelId?: string;
37
38
  }
38
39
  export type PickersArrowSwitcherOwnerState = PickersArrowSwitcherProps;
39
40
  export interface PickersArrowSwitcherSlotPropsOverrides {
@@ -12,5 +12,5 @@ export declare function useNextMonthDisabled<TDate extends PickerValidDate>(mont
12
12
  export declare function usePreviousMonthDisabled<TDate extends PickerValidDate>(month: TDate, { disablePast, minDate, timezone, }: Pick<MonthValidationOptions<TDate>, 'disablePast' | 'minDate' | 'timezone'>): boolean;
13
13
  export declare function useMeridiemMode<TDate extends PickerValidDate>(date: TDate | null, ampm: boolean | undefined, onChange: PickerOnChangeFn<TDate>, selectionState?: PickerSelectionState): {
14
14
  meridiemMode: import("../utils/time-utils").Meridiem | null;
15
- handleMeridiemChange: (mode: 'am' | 'pm') => void;
15
+ handleMeridiemChange: (mode: "am" | "pm") => void;
16
16
  };
@@ -9,11 +9,11 @@ export interface UseDefaultizedTimeFieldBaseProps extends BaseTimeValidationProp
9
9
  format?: string;
10
10
  }
11
11
  export declare const useDefaultizedTimeField: <TDate extends PickerValidDate, TKnownProps extends UseDefaultizedTimeFieldBaseProps & {
12
- ampm?: boolean | undefined;
12
+ ampm?: boolean;
13
13
  }, TAllProps extends {}>(props: TKnownProps & TAllProps) => TAllProps & DefaultizedProps<TKnownProps, keyof UseDefaultizedTimeFieldBaseProps>;
14
14
  export interface UseDefaultizedDateTimeFieldBaseProps<TDate extends PickerValidDate> extends BaseDateValidationProps<TDate>, BaseTimeValidationProps {
15
15
  format?: string;
16
16
  }
17
17
  export declare const useDefaultizedDateTimeField: <TDate extends PickerValidDate, TKnownProps extends UseDefaultizedDateTimeFieldBaseProps<TDate> & DateTimeValidationProps<TDate> & TimeValidationProps<TDate> & {
18
- ampm?: boolean | undefined;
18
+ ampm?: boolean;
19
19
  }, TAllProps extends {}>(props: TKnownProps & TAllProps) => TAllProps & DefaultizedProps<TKnownProps, keyof UseDefaultizedDateTimeFieldBaseProps<any>>;
@@ -1,5 +1,5 @@
1
- import { UseFieldParams, UseFieldResponse, UseFieldCommonForwardedProps, UseFieldInternalProps } from './useField.types';
1
+ import { UseFieldParams, UseFieldResponse, UseFieldCommonForwardedProps, UseFieldInternalProps, UseFieldForwardedProps } from './useField.types';
2
2
  import { PickerValidDate, FieldSection } from '../../../models';
3
- export declare const useField: <TValue, TDate extends PickerValidDate, TSection extends FieldSection, TEnableAccessibleFieldDOMStructure extends boolean, TForwardedProps extends UseFieldCommonForwardedProps & (TEnableAccessibleFieldDOMStructure extends false ? import("./useField.types").UseFieldV6ForwardedProps : import("./useField.types").UseFieldV7ForwardedProps), TInternalProps extends UseFieldInternalProps<any, any, any, TEnableAccessibleFieldDOMStructure, any> & {
4
- minutesStep?: number | undefined;
3
+ export declare const useField: <TValue, TDate extends PickerValidDate, TSection extends FieldSection, TEnableAccessibleFieldDOMStructure extends boolean, TForwardedProps extends UseFieldCommonForwardedProps & UseFieldForwardedProps<TEnableAccessibleFieldDOMStructure>, TInternalProps extends UseFieldInternalProps<any, any, any, TEnableAccessibleFieldDOMStructure, any> & {
4
+ minutesStep?: number;
5
5
  }>(params: UseFieldParams<TValue, TDate, TSection, TEnableAccessibleFieldDOMStructure, TForwardedProps, TInternalProps>) => UseFieldResponse<TEnableAccessibleFieldDOMStructure, TForwardedProps>;
@@ -1,6 +1,6 @@
1
1
  import { AvailableAdjustKeyCode, FieldSectionsValueBoundaries, SectionOrdering, FieldSectionValueBoundaries, FieldParsedSelectedSections } from './useField.types';
2
2
  import { FieldSectionType, FieldValueType, FieldSection, MuiPickersAdapter, FieldSectionContentType, PickersTimezone, PickerValidDate, FieldSelectedSections } from '../../../models';
3
- export declare const getDateSectionConfigFromFormatToken: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, formatToken: string) => Pick<FieldSection, 'type' | 'contentType'> & {
3
+ export declare const getDateSectionConfigFromFormatToken: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, formatToken: string) => Pick<FieldSection, "type" | "contentType"> & {
4
4
  maxLength: number | undefined;
5
5
  };
6
6
  export declare const getDaysInWeekStr: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, timezone: PickersTimezone, format: string) => string[];
@@ -16,11 +16,11 @@ export declare const isStringNumber: (valueStr: string, localizedDigits: string[
16
16
  * Warning: Should only be called with non-localized digits. Call `removeLocalizedDigits` with your value if needed.
17
17
  */
18
18
  export declare const cleanLeadingZeros: (valueStr: string, size: number) => string;
19
- export declare const cleanDigitSectionValue: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, value: number, sectionBoundaries: FieldSectionValueBoundaries<TDate, any>, localizedDigits: string[], section: Pick<FieldSection, 'format' | 'type' | 'contentType' | 'hasLeadingZerosInFormat' | 'hasLeadingZerosInInput' | 'maxLength'>) => string;
19
+ export declare const cleanDigitSectionValue: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, value: number, sectionBoundaries: FieldSectionValueBoundaries<TDate, any>, localizedDigits: string[], section: Pick<FieldSection, "format" | "type" | "contentType" | "hasLeadingZerosInFormat" | "hasLeadingZerosInInput" | "maxLength">) => string;
20
20
  export declare const adjustSectionValue: <TDate extends PickerValidDate, TSection extends FieldSection>(utils: MuiPickersAdapter<TDate>, timezone: PickersTimezone, section: TSection, keyCode: AvailableAdjustKeyCode, sectionsValueBoundaries: FieldSectionsValueBoundaries<TDate>, localizedDigits: string[], activeDate: TDate | null, stepsAttributes?: {
21
21
  minutesStep?: number;
22
22
  }) => string;
23
- export declare const getSectionVisibleValue: (section: FieldSection, target: 'input-rtl' | 'input-ltr' | 'non-input', localizedDigits: string[]) => string;
23
+ export declare const getSectionVisibleValue: (section: FieldSection, target: "input-rtl" | "input-ltr" | "non-input", localizedDigits: string[]) => string;
24
24
  export declare const changeSectionValueFormat: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, valueStr: string, currentFormat: string, newFormat: string) => string;
25
25
  export declare const doesSectionFormatHaveLeadingZeros: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, timezone: PickersTimezone, contentType: FieldSectionContentType, sectionType: FieldSectionType, format: string) => boolean;
26
26
  /**
@@ -103,7 +103,8 @@ export const applyLocalizedDigits = (valueStr, localizedDigits) => {
103
103
  };
104
104
  export const isStringNumber = (valueStr, localizedDigits) => {
105
105
  const nonLocalizedValueStr = removeLocalizedDigits(valueStr, localizedDigits);
106
- return !Number.isNaN(Number(nonLocalizedValueStr));
106
+ // `Number(' ')` returns `0` even if ' ' is not a valid number.
107
+ return nonLocalizedValueStr !== ' ' && !Number.isNaN(Number(nonLocalizedValueStr));
107
108
  };
108
109
 
109
110
  /**
@@ -103,6 +103,13 @@ export const useFieldV6TextField = params => {
103
103
  inputRef.current.setSelectionRange(selectionStart, selectionEnd);
104
104
  }
105
105
  }
106
+ setTimeout(() => {
107
+ // handle case when the selection is not updated correctly
108
+ // could happen on Android
109
+ if (inputRef.current && inputRef.current === getActiveElement(document) && (inputRef.current.selectionStart !== selectionStart || inputRef.current.selectionEnd !== selectionEnd)) {
110
+ interactions.syncSelectionToDOM();
111
+ }
112
+ });
106
113
  }
107
114
 
108
115
  // Even reading this variable seems to do the trick, but also setting it just to make use of it
@@ -265,10 +272,9 @@ export const useFieldV6TextField = params => {
265
272
  if (keyPressed.length === 0) {
266
273
  if (isAndroid()) {
267
274
  setTempAndroidValueStr(valueStr);
268
- } else {
269
- resetCharacterQuery();
270
- clearActiveSection();
271
275
  }
276
+ resetCharacterQuery();
277
+ clearActiveSection();
272
278
  return;
273
279
  }
274
280
  applyCharacterEditing({
@@ -119,7 +119,7 @@ export const usePickerValue = ({
119
119
  const {
120
120
  onAccept,
121
121
  onChange,
122
- value: inValue,
122
+ value: inValueWithoutRenderTimezone,
123
123
  defaultValue: inDefaultValue,
124
124
  closeOnSelect = wrapperVariant === 'desktop',
125
125
  timezone: timezoneProp
@@ -129,15 +129,15 @@ export const usePickerValue = ({
129
129
  } = React.useRef(inDefaultValue);
130
130
  const {
131
131
  current: isControlled
132
- } = React.useRef(inValue !== undefined);
132
+ } = React.useRef(inValueWithoutRenderTimezone !== undefined);
133
133
 
134
134
  /* eslint-disable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
135
135
  if (process.env.NODE_ENV !== 'production') {
136
136
  React.useEffect(() => {
137
- if (isControlled !== (inValue !== undefined)) {
137
+ if (isControlled !== (inValueWithoutRenderTimezone !== undefined)) {
138
138
  console.error([`MUI X: A component is changing the ${isControlled ? '' : 'un'}controlled value of a picker to be ${isControlled ? 'un' : ''}controlled.`, 'Elements should not switch from uncontrolled to controlled (or vice versa).', `Decide between using a controlled or uncontrolled value` + 'for the lifetime of the component.', "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", 'More info: https://fb.me/react-controlled-components'].join('\n'));
139
139
  }
140
- }, [inValue]);
140
+ }, [inValueWithoutRenderTimezone]);
141
141
  React.useEffect(() => {
142
142
  if (!isControlled && defaultValue !== inDefaultValue) {
143
143
  console.error([`MUI X: A component is changing the defaultValue of an uncontrolled picker after being initialized. ` + `To suppress this warning opt to use a controlled value.`].join('\n'));
@@ -152,10 +152,21 @@ export const usePickerValue = ({
152
152
  isOpen,
153
153
  setIsOpen
154
154
  } = useOpenState(props);
155
+ const {
156
+ timezone,
157
+ value: inValueWithTimezoneToRender,
158
+ handleValueChange
159
+ } = useValueWithTimezone({
160
+ timezone: timezoneProp,
161
+ value: inValueWithoutRenderTimezone,
162
+ defaultValue,
163
+ onChange,
164
+ valueManager
165
+ });
155
166
  const [dateState, setDateState] = React.useState(() => {
156
167
  let initialValue;
157
- if (inValue !== undefined) {
158
- initialValue = inValue;
168
+ if (inValueWithTimezoneToRender !== undefined) {
169
+ initialValue = inValueWithTimezoneToRender;
159
170
  } else if (defaultValue !== undefined) {
160
171
  initialValue = defaultValue;
161
172
  } else {
@@ -165,20 +176,10 @@ export const usePickerValue = ({
165
176
  draft: initialValue,
166
177
  lastPublishedValue: initialValue,
167
178
  lastCommittedValue: initialValue,
168
- lastControlledValue: inValue,
179
+ lastControlledValue: inValueWithTimezoneToRender,
169
180
  hasBeenModifiedSinceMount: false
170
181
  };
171
182
  });
172
- const {
173
- timezone,
174
- handleValueChange
175
- } = useValueWithTimezone({
176
- timezone: timezoneProp,
177
- value: inValue,
178
- defaultValue,
179
- onChange,
180
- valueManager
181
- });
182
183
  useValidation(_extends({}, props, {
183
184
  value: dateState.draft,
184
185
  timezone
@@ -200,38 +201,44 @@ export const usePickerValue = ({
200
201
  lastCommittedValue: shouldCommit ? action.value : prev.lastCommittedValue,
201
202
  hasBeenModifiedSinceMount: true
202
203
  }));
203
- if (shouldPublish) {
204
- const validationError = action.name === 'setValueFromField' ? action.context.validationError : validator({
205
- adapter,
206
- value: action.value,
207
- props: _extends({}, props, {
204
+ let cachedContext = null;
205
+ const getContext = () => {
206
+ if (!cachedContext) {
207
+ const validationError = action.name === 'setValueFromField' ? action.context.validationError : validator({
208
+ adapter,
208
209
  value: action.value,
209
- timezone
210
- })
211
- });
212
- const context = {
213
- validationError
214
- };
215
- if (action.name === 'setValueFromShortcut') {
216
- context.shortcut = action.shortcut;
210
+ props: _extends({}, props, {
211
+ value: action.value,
212
+ timezone
213
+ })
214
+ });
215
+ cachedContext = {
216
+ validationError
217
+ };
218
+ if (action.name === 'setValueFromShortcut') {
219
+ cachedContext.shortcut = action.shortcut;
220
+ }
217
221
  }
218
- handleValueChange(action.value, context);
222
+ return cachedContext;
223
+ };
224
+ if (shouldPublish) {
225
+ handleValueChange(action.value, getContext());
219
226
  }
220
227
  if (shouldCommit && onAccept) {
221
- onAccept(action.value);
228
+ onAccept(action.value, getContext());
222
229
  }
223
230
  if (shouldClose) {
224
231
  setIsOpen(false);
225
232
  }
226
233
  });
227
- if (inValue !== undefined && (dateState.lastControlledValue === undefined || !valueManager.areValuesEqual(utils, dateState.lastControlledValue, inValue))) {
228
- const isUpdateComingFromPicker = valueManager.areValuesEqual(utils, dateState.draft, inValue);
234
+ if (inValueWithTimezoneToRender !== undefined && (dateState.lastControlledValue === undefined || !valueManager.areValuesEqual(utils, dateState.lastControlledValue, inValueWithTimezoneToRender))) {
235
+ const isUpdateComingFromPicker = valueManager.areValuesEqual(utils, dateState.draft, inValueWithTimezoneToRender);
229
236
  setDateState(prev => _extends({}, prev, {
230
- lastControlledValue: inValue
237
+ lastControlledValue: inValueWithTimezoneToRender
231
238
  }, isUpdateComingFromPicker ? {} : {
232
- lastCommittedValue: inValue,
233
- lastPublishedValue: inValue,
234
- draft: inValue,
239
+ lastCommittedValue: inValueWithTimezoneToRender,
240
+ lastPublishedValue: inValueWithTimezoneToRender,
241
+ draft: inValueWithTimezoneToRender,
235
242
  hasBeenModifiedSinceMount: true
236
243
  }));
237
244
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { FieldChangeHandlerContext, UseFieldInternalProps } from '../useField';
3
2
  import { InferError, Validator } from '../useValidation';
4
3
  import { UseFieldValidationProps } from '../useField/useField.types';
@@ -193,9 +192,11 @@ export interface UsePickerValueBaseProps<TValue, TError> {
193
192
  /**
194
193
  * Callback fired when the value is accepted.
195
194
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
195
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
196
196
  * @param {TValue} value The value that was just accepted.
197
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
197
198
  */
198
- onAccept?: (value: TValue) => void;
199
+ onAccept?: (value: TValue, context: PickerChangeHandlerContext<TError>) => void;
199
200
  /**
200
201
  * Callback fired when the error associated to the current value changes.
201
202
  * If the error has a non-null value, then the `TextField` will be rendered in `error` state.
@@ -39,6 +39,7 @@ export const usePickerViews = ({
39
39
  onClose
40
40
  } = propsFromPickerValue;
41
41
  const {
42
+ view: inView,
42
43
  views,
43
44
  openTo,
44
45
  onViewChange,
@@ -54,7 +55,7 @@ export const usePickerViews = ({
54
55
  setFocusedView,
55
56
  setValueAndGoToNextView
56
57
  } = useViews({
57
- view: undefined,
58
+ view: inView,
58
59
  views,
59
60
  openTo,
60
61
  onChange,
@@ -17,7 +17,7 @@ export declare const applyDefaultDate: <TDate extends PickerValidDate>(utils: Mu
17
17
  export declare const areDatesEqual: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, a: TDate, b: TDate) => boolean;
18
18
  export declare const getMonthsInYear: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, year: TDate) => TDate[];
19
19
  export declare const getTodayDate: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, timezone: PickersTimezone, valueType?: FieldValueType) => TDate;
20
- export declare const formatMeridiem: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, meridiem: 'am' | 'pm') => string;
20
+ export declare const formatMeridiem: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, meridiem: "am" | "pm") => string;
21
21
  export declare const isDatePickerView: (view: DateOrTimeViewWithMeridiem) => view is DateView;
22
22
  export declare const resolveDateFormat: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, { format, views }: {
23
23
  format?: string;
@@ -1,6 +1,6 @@
1
1
  import { DateOrTimeView } from '../../models';
2
2
  import { DateOrTimeViewWithMeridiem } from '../models';
3
- export declare const areViewsEqual: <TView extends DateOrTimeView>(views: ReadonlyArray<DateOrTimeView>, expectedViews: TView[]) => views is readonly TView[];
3
+ export declare const areViewsEqual: <TView extends DateOrTimeView>(views: ReadonlyArray<DateOrTimeView>, expectedViews: TView[]) => views is ReadonlyArray<TView>;
4
4
  export declare const applyDefaultViewProps: <TView extends DateOrTimeViewWithMeridiem>({ openTo, defaultOpenTo, views, defaultViews, }: {
5
5
  openTo: TView | undefined;
6
6
  defaultOpenTo: TView;
@@ -1,4 +1,4 @@
1
1
  export declare const buildDeprecatedPropsWarning: (message: string | string[]) => (deprecatedProps: {
2
2
  [key: string]: any;
3
3
  }) => void;
4
- export declare const buildWarning: (message: string | string[], gravity?: 'warning' | 'error') => () => void;
4
+ export declare const buildWarning: (message: string | string[], gravity?: "warning" | "error") => () => void;
package/locales/daDK.js CHANGED
@@ -17,11 +17,10 @@ const daDKPickers = {
17
17
  // DateRange labels
18
18
  start: 'Start',
19
19
  end: 'Slut',
20
- // startDate: 'Start date',
21
- // startTime: 'Start time',
22
- // endDate: 'End date',
23
- // endTime: 'End time',
24
-
20
+ startDate: 'Start dato',
21
+ startTime: 'Start tid',
22
+ endDate: 'Slut date',
23
+ endTime: 'Slut tid',
25
24
  // Action bar
26
25
  cancelButtonLabel: 'Annuller',
27
26
  clearButtonLabel: 'Ryd',
@@ -47,8 +46,7 @@ const daDKPickers = {
47
46
  // Open picker labels
48
47
  openDatePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `Vælg dato, valgte dato er ${utils.format(value, 'fullDate')}` : 'Vælg dato',
49
48
  openTimePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `Vælg tidspunkt, valgte tidspunkt er ${utils.format(value, 'fullTime')}` : 'Vælg tidspunkt',
50
- // fieldClearLabel: 'Clear value',
51
-
49
+ fieldClearLabel: 'ryd felt',
52
50
  // Table labels
53
51
  timeTableLabel: 'vælg tidspunkt',
54
52
  dateTableLabel: 'vælg dato',
@@ -60,19 +58,17 @@ const daDKPickers = {
60
58
  fieldHoursPlaceholder: () => 'hh',
61
59
  fieldMinutesPlaceholder: () => 'mm',
62
60
  fieldSecondsPlaceholder: () => 'ss',
63
- fieldMeridiemPlaceholder: () => 'aa'
64
-
61
+ fieldMeridiemPlaceholder: () => 'aa',
65
62
  // View names
66
- // year: 'Year',
67
- // month: 'Month',
68
- // day: 'Day',
69
- // weekDay: 'Week day',
70
- // hours: 'Hours',
71
- // minutes: 'Minutes',
72
- // seconds: 'Seconds',
73
- // meridiem: 'Meridiem',
74
-
63
+ year: 'år',
64
+ month: 'måned',
65
+ day: 'dag',
66
+ weekDay: 'ugedag',
67
+ hours: 'timer',
68
+ minutes: 'minutter',
69
+ seconds: 'sekunder',
70
+ meridiem: 'middag',
75
71
  // Common
76
- // empty: 'Empty',
72
+ empty: 'tom'
77
73
  };
78
74
  export const daDK = getPickersLocalization(daDKPickers);
@@ -130,6 +130,7 @@ export class AdapterDateFnsJalali extends AdapterDateFnsBase {
130
130
  longFormatters,
131
131
  lib: 'date-fns-jalali'
132
132
  });
133
+ // TODO: explicit return types can be removed once there is only one date-fns version supported
133
134
  this.parse = (value, format) => {
134
135
  if (value === '') {
135
136
  return null;
@@ -90,6 +90,7 @@ export class AdapterDateFns extends AdapterDateFnsBase {
90
90
  formats,
91
91
  longFormatters
92
92
  });
93
+ // TODO: explicit return types can be removed once there is only one date-fns version supported
93
94
  this.parse = (value, format) => {
94
95
  if (value === '') {
95
96
  return null;
@@ -167,7 +167,9 @@ process.env.NODE_ENV !== "production" ? DatePicker.propTypes = {
167
167
  /**
168
168
  * Callback fired when the value is accepted.
169
169
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
170
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
170
171
  * @param {TValue} value The value that was just accepted.
172
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
171
173
  */
172
174
  onAccept: PropTypes.func,
173
175
  /**
@@ -205,7 +205,9 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
205
205
  /**
206
206
  * Callback fired when the value is accepted.
207
207
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
208
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
208
209
  * @param {TValue} value The value that was just accepted.
210
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
209
211
  */
210
212
  onAccept: PropTypes.func,
211
213
  /**
@@ -16,7 +16,7 @@ import { useMeridiemMode } from '../internals/hooks/date-helpers-hooks';
16
16
  import { MULTI_SECTION_CLOCK_SECTION_WIDTH } from '../internals/constants/dimensions';
17
17
  import { formatMeridiem } from '../internals/utils/date-utils';
18
18
  import { pickersToolbarTextClasses } from '../internals/components/pickersToolbarTextClasses';
19
- import { pickersToolbarClasses } from '../internals';
19
+ import { pickersToolbarClasses } from '../internals/components/pickersToolbarClasses';
20
20
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
21
21
  const useUtilityClasses = ownerState => {
22
22
  const {
@@ -182,7 +182,9 @@ DesktopDatePicker.propTypes = {
182
182
  /**
183
183
  * Callback fired when the value is accepted.
184
184
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
185
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
185
186
  * @param {TValue} value The value that was just accepted.
187
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
186
188
  */
187
189
  onAccept: PropTypes.func,
188
190
  /**
@@ -17,10 +17,12 @@ import { useDesktopPicker } from '../internals/hooks/useDesktopPicker';
17
17
  import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
18
18
  import { resolveDateTimeFormat, resolveTimeViewsResponse } from '../internals/utils/date-time-utils';
19
19
  import { renderDigitalClockTimeView, renderMultiSectionDigitalClockTimeView } from '../timeViewRenderers';
20
- import { VIEW_HEIGHT, isDatePickerView, isInternalTimeView } from '../internals';
21
20
  import { multiSectionDigitalClockClasses, multiSectionDigitalClockSectionClasses } from '../MultiSectionDigitalClock';
22
21
  import { digitalClockClasses } from '../DigitalClock';
23
22
  import { DesktopDateTimePickerLayout } from './DesktopDateTimePickerLayout';
23
+ import { VIEW_HEIGHT } from '../internals/constants/dimensions';
24
+ import { isInternalTimeView } from '../internals/utils/time-utils';
25
+ import { isDatePickerView } from '../internals/utils/date-utils';
24
26
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
25
27
  const rendererInterceptor = function rendererInterceptor(inViewRenderers, popperView, rendererProps) {
26
28
  const {
@@ -305,7 +307,9 @@ DesktopDateTimePicker.propTypes = {
305
307
  /**
306
308
  * Callback fired when the value is accepted.
307
309
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
310
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
308
311
  * @param {TValue} value The value that was just accepted.
312
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
309
313
  */
310
314
  onAccept: PropTypes.func,
311
315
  /**
@@ -193,7 +193,9 @@ DesktopTimePicker.propTypes = {
193
193
  /**
194
194
  * Callback fired when the value is accepted.
195
195
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
196
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
196
197
  * @param {TValue} value The value that was just accepted.
198
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
197
199
  */
198
200
  onAccept: PropTypes.func,
199
201
  /**
@@ -179,7 +179,9 @@ MobileDatePicker.propTypes = {
179
179
  /**
180
180
  * Callback fired when the value is accepted.
181
181
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
182
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
182
183
  * @param {TValue} value The value that was just accepted.
184
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
183
185
  */
184
186
  onAccept: PropTypes.func,
185
187
  /**
@@ -227,7 +227,9 @@ MobileDateTimePicker.propTypes = {
227
227
  /**
228
228
  * Callback fired when the value is accepted.
229
229
  * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
230
+ * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
230
231
  * @param {TValue} value The value that was just accepted.
232
+ * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
231
233
  */
232
234
  onAccept: PropTypes.func,
233
235
  /**