@mui/x-date-pickers 9.0.0 → 9.0.2

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.
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v9.0.0
2
+ * @mui/x-date-pickers v9.0.2
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v9.0.0
2
+ * @mui/x-date-pickers v9.0.2
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -106,8 +106,7 @@ interface PickerFieldUIContextValue {
106
106
  export declare function mergeSlotProps<TProps extends {}, TOwnerState extends FieldOwnerState>(slotPropsA: SlotComponentPropsFromProps<TProps, {}, TOwnerState> | undefined, slotPropsB: SlotComponentPropsFromProps<TProps, {}, TOwnerState> | undefined): Partial<TProps> | ((ownerState: TOwnerState) => {}) | undefined;
107
107
  /**
108
108
  * The `textField` slot props cannot be handled inside `PickerFieldUI` because it would be a breaking change to not pass the enriched props to `useField`.
109
- * Once the non-accessible DOM structure will be removed, we will be able to remove the `textField` slot and clean this logic.
110
- * TODO: Address with the needed support for the `textField` slotProps given the change of minimum version of MUI.
109
+ * TODO v10: Remove the `textField` slot and clean this logic up.
111
110
  */
112
111
  export declare function useFieldTextFieldProps<TProps extends UseFieldOwnerStateParameters>(parameters: UseFieldTextFieldPropsParameters): TProps;
113
112
  interface UseFieldTextFieldPropsParameters {
@@ -106,8 +106,7 @@ interface PickerFieldUIContextValue {
106
106
  export declare function mergeSlotProps<TProps extends {}, TOwnerState extends FieldOwnerState>(slotPropsA: SlotComponentPropsFromProps<TProps, {}, TOwnerState> | undefined, slotPropsB: SlotComponentPropsFromProps<TProps, {}, TOwnerState> | undefined): Partial<TProps> | ((ownerState: TOwnerState) => {}) | undefined;
107
107
  /**
108
108
  * The `textField` slot props cannot be handled inside `PickerFieldUI` because it would be a breaking change to not pass the enriched props to `useField`.
109
- * Once the non-accessible DOM structure will be removed, we will be able to remove the `textField` slot and clean this logic.
110
- * TODO: Address with the needed support for the `textField` slotProps given the change of minimum version of MUI.
109
+ * TODO v10: Remove the `textField` slot and clean this logic up.
111
110
  */
112
111
  export declare function useFieldTextFieldProps<TProps extends UseFieldOwnerStateParameters>(parameters: UseFieldTextFieldPropsParameters): TProps;
113
112
  interface UseFieldTextFieldPropsParameters {
@@ -250,8 +250,7 @@ function mergeSlotProps(slotPropsA, slotPropsB) {
250
250
 
251
251
  /**
252
252
  * The `textField` slot props cannot be handled inside `PickerFieldUI` because it would be a breaking change to not pass the enriched props to `useField`.
253
- * Once the non-accessible DOM structure will be removed, we will be able to remove the `textField` slot and clean this logic.
254
- * TODO: Address with the needed support for the `textField` slotProps given the change of minimum version of MUI.
253
+ * TODO v10: Remove the `textField` slot and clean this logic up.
255
254
  */
256
255
  function useFieldTextFieldProps(parameters) {
257
256
  const {
@@ -237,8 +237,7 @@ export function mergeSlotProps(slotPropsA, slotPropsB) {
237
237
 
238
238
  /**
239
239
  * The `textField` slot props cannot be handled inside `PickerFieldUI` because it would be a breaking change to not pass the enriched props to `useField`.
240
- * Once the non-accessible DOM structure will be removed, we will be able to remove the `textField` slot and clean this logic.
241
- * TODO: Address with the needed support for the `textField` slotProps given the change of minimum version of MUI.
240
+ * TODO v10: Remove the `textField` slot and clean this logic up.
242
241
  */
243
242
  export function useFieldTextFieldProps(parameters) {
244
243
  const {
@@ -138,12 +138,25 @@ const useField = parameters => {
138
138
  rootProps.onKeyDown(event);
139
139
  });
140
140
  const handleRootBlur = (0, _useEventCallback.default)(event => {
141
- onBlur?.(event);
142
141
  rootProps.onBlur(event);
142
+ // Skip the user callback when focus is only moving to another element inside the field
143
+ // (e.g. the section that gains focus after the focusable root gives it up).
144
+ const next = event.relatedTarget;
145
+ if (domGetters.isReady() && next instanceof Node && domGetters.getRoot().contains(next)) {
146
+ return;
147
+ }
148
+ onBlur?.(event);
143
149
  });
144
150
  const handleRootFocus = (0, _useEventCallback.default)(event => {
145
- onFocus?.(event);
146
151
  rootProps.onFocus(event);
152
+ // Skip the user callback when focus is only arriving from another element inside the field
153
+ // (e.g. the focusable root receiving it before it is forwarded to a section, and the section
154
+ // focus event bubbling back up to the root).
155
+ const previous = event.relatedTarget;
156
+ if (domGetters.isReady() && previous instanceof Node && domGetters.getRoot().contains(previous)) {
157
+ return;
158
+ }
159
+ onFocus?.(event);
147
160
  });
148
161
  const handleRootClick = (0, _useEventCallback.default)(event => {
149
162
  // The click event on the clear or open button would propagate to the input, trigger this handler and result in an inadvertent section selection.
@@ -131,12 +131,25 @@ export const useField = parameters => {
131
131
  rootProps.onKeyDown(event);
132
132
  });
133
133
  const handleRootBlur = useEventCallback(event => {
134
- onBlur?.(event);
135
134
  rootProps.onBlur(event);
135
+ // Skip the user callback when focus is only moving to another element inside the field
136
+ // (e.g. the section that gains focus after the focusable root gives it up).
137
+ const next = event.relatedTarget;
138
+ if (domGetters.isReady() && next instanceof Node && domGetters.getRoot().contains(next)) {
139
+ return;
140
+ }
141
+ onBlur?.(event);
136
142
  });
137
143
  const handleRootFocus = useEventCallback(event => {
138
- onFocus?.(event);
139
144
  rootProps.onFocus(event);
145
+ // Skip the user callback when focus is only arriving from another element inside the field
146
+ // (e.g. the focusable root receiving it before it is forwarded to a section, and the section
147
+ // focus event bubbling back up to the root).
148
+ const previous = event.relatedTarget;
149
+ if (domGetters.isReady() && previous instanceof Node && domGetters.getRoot().contains(previous)) {
150
+ return;
151
+ }
152
+ onFocus?.(event);
140
153
  });
141
154
  const handleRootClick = useEventCallback(event => {
142
155
  // The click event on the clear or open button would propagate to the input, trigger this handler and result in an inadvertent section selection.
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.validateSections = exports.removeLocalizedDigits = exports.parseSelectedSections = exports.mergeDateIntoReferenceDate = exports.isStringNumber = exports.isAndroid = exports.getSectionsBoundaries = exports.getSectionVisibleValue = exports.getSectionOrder = exports.getLocalizedDigits = exports.getLetterEditingOptions = exports.getDaysInWeekStr = exports.getDateSectionConfigFromFormatToken = exports.getDateFromDateSections = exports.doesSectionFormatHaveLeadingZeros = exports.createDateStrForHiddenInputFromSections = exports.cleanLeadingZeros = exports.cleanDigitSectionValue = exports.changeSectionValueFormat = exports.applyLocalizedDigits = exports.FORMAT_SECONDS_NO_LEADING_ZEROS = void 0;
8
8
  var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
9
9
  var _dateUtils = require("../../utils/date-utils");
10
+ var _timeUtils = require("../../utils/time-utils");
10
11
  const getDateSectionConfigFromFormatToken = (adapter, formatToken) => {
11
12
  const config = adapter.formatTokenMap[formatToken];
12
13
  if (config == null) {
@@ -386,15 +387,8 @@ const transferDateSectionValue = (adapter, section, dateToTransferFrom, dateToTr
386
387
  }
387
388
  case 'meridiem':
388
389
  {
389
- const isAM = adapter.getHours(dateToTransferFrom) < 12;
390
- const mergedDateHours = adapter.getHours(dateToTransferTo);
391
- if (isAM && mergedDateHours >= 12) {
392
- return adapter.addHours(dateToTransferTo, -12);
393
- }
394
- if (!isAM && mergedDateHours < 12) {
395
- return adapter.addHours(dateToTransferTo, 12);
396
- }
397
- return dateToTransferTo;
390
+ const meridiem = adapter.getHours(dateToTransferFrom) < 12 ? 'am' : 'pm';
391
+ return (0, _timeUtils.convertToMeridiem)(dateToTransferTo, meridiem, true, adapter);
398
392
  }
399
393
  case 'hours':
400
394
  {
@@ -1,5 +1,6 @@
1
1
  import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
2
2
  import { getMonthsInYear } from "../../utils/date-utils.mjs";
3
+ import { convertToMeridiem } from "../../utils/time-utils.mjs";
3
4
  export const getDateSectionConfigFromFormatToken = (adapter, formatToken) => {
4
5
  const config = adapter.formatTokenMap[formatToken];
5
6
  if (config == null) {
@@ -363,15 +364,8 @@ const transferDateSectionValue = (adapter, section, dateToTransferFrom, dateToTr
363
364
  }
364
365
  case 'meridiem':
365
366
  {
366
- const isAM = adapter.getHours(dateToTransferFrom) < 12;
367
- const mergedDateHours = adapter.getHours(dateToTransferTo);
368
- if (isAM && mergedDateHours >= 12) {
369
- return adapter.addHours(dateToTransferTo, -12);
370
- }
371
- if (!isAM && mergedDateHours < 12) {
372
- return adapter.addHours(dateToTransferTo, 12);
373
- }
374
- return dateToTransferTo;
367
+ const meridiem = adapter.getHours(dateToTransferFrom) < 12 ? 'am' : 'pm';
368
+ return convertToMeridiem(dateToTransferTo, meridiem, true, adapter);
375
369
  }
376
370
  case 'hours':
377
371
  {