@mui/x-date-pickers 6.0.1 → 6.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/AdapterDateFns/index.js +1 -0
- package/AdapterDayjs/index.js +1 -0
- package/AdapterMoment/index.js +1 -0
- package/AdapterMomentHijri/index.d.ts +1 -1
- package/CHANGELOG.md +58 -5
- package/index.js +1 -1
- package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +8 -2
- package/internals/components/PickersModalDialog.d.ts +2 -2
- package/internals/components/PickersPopper.d.ts +1 -1
- package/internals/hooks/useField/useField.js +11 -5
- package/internals/hooks/useField/useField.types.d.ts +13 -8
- package/internals/hooks/useField/useField.utils.d.ts +3 -3
- package/internals/hooks/useField/useField.utils.js +63 -35
- package/internals/hooks/useField/useFieldCharacterEditing.js +4 -9
- package/internals/hooks/useField/useFieldState.js +43 -37
- package/internals/utils/valueManagers.js +11 -7
- package/legacy/AdapterDateFns/index.js +1 -0
- package/legacy/AdapterDayjs/index.js +1 -0
- package/legacy/AdapterMoment/index.js +1 -0
- package/legacy/index.js +1 -1
- package/legacy/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +8 -2
- package/legacy/internals/hooks/useField/useField.js +11 -5
- package/legacy/internals/hooks/useField/useField.utils.js +64 -36
- package/legacy/internals/hooks/useField/useFieldCharacterEditing.js +4 -9
- package/legacy/internals/hooks/useField/useFieldState.js +45 -39
- package/legacy/internals/utils/valueManagers.js +4 -0
- package/legacy/locales/deDE.js +8 -5
- package/legacy/locales/frFR.js +30 -15
- package/legacy/locales/heIL.js +71 -0
- package/legacy/locales/index.js +1 -0
- package/legacy/tests/describeValue/testPickerOpenCloseLifeCycle.js +20 -1
- package/locales/deDE.js +4 -5
- package/locales/frFR.js +12 -15
- package/locales/heIL.d.ts +51 -0
- package/locales/heIL.js +57 -0
- package/locales/index.d.ts +1 -0
- package/locales/index.js +1 -0
- package/modern/AdapterDateFns/index.js +1 -0
- package/modern/AdapterDayjs/index.js +1 -0
- package/modern/AdapterMoment/index.js +1 -0
- package/modern/index.js +1 -1
- package/modern/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +8 -2
- package/modern/internals/hooks/useField/useField.js +11 -5
- package/modern/internals/hooks/useField/useField.utils.js +63 -35
- package/modern/internals/hooks/useField/useFieldCharacterEditing.js +4 -9
- package/modern/internals/hooks/useField/useFieldState.js +43 -37
- package/modern/internals/utils/valueManagers.js +11 -7
- package/modern/locales/deDE.js +4 -5
- package/modern/locales/frFR.js +12 -15
- package/modern/locales/heIL.js +57 -0
- package/modern/locales/index.js +1 -0
- package/modern/tests/describeValue/testPickerOpenCloseLifeCycle.js +20 -1
- package/node/AdapterDateFns/index.js +1 -0
- package/node/AdapterDayjs/index.js +1 -0
- package/node/AdapterMoment/index.js +1 -0
- package/node/index.js +1 -1
- package/node/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +8 -2
- package/node/internals/hooks/useField/useField.js +11 -5
- package/node/internals/hooks/useField/useField.utils.js +66 -38
- package/node/internals/hooks/useField/useFieldCharacterEditing.js +3 -8
- package/node/internals/hooks/useField/useFieldState.js +43 -37
- package/node/internals/utils/valueManagers.js +11 -7
- package/node/locales/deDE.js +4 -5
- package/node/locales/frFR.js +12 -15
- package/node/locales/heIL.js +64 -0
- package/node/locales/index.js +11 -0
- package/node/tests/describeValue/testPickerOpenCloseLifeCycle.js +19 -0
- package/package.json +2 -2
- package/tests/describeValue/testPickerOpenCloseLifeCycle.js +20 -1
|
@@ -41,19 +41,6 @@ export const getDaysInWeekStr = (utils, format) => {
|
|
|
41
41
|
}
|
|
42
42
|
return elements.map(weekDay => utils.formatByString(weekDay, format));
|
|
43
43
|
};
|
|
44
|
-
export const cleanLeadingZerosInNumericSectionValue = (utils, format, value) => {
|
|
45
|
-
const size = utils.formatByString(utils.date(), format).length;
|
|
46
|
-
let cleanValue = value;
|
|
47
|
-
|
|
48
|
-
// We remove the leading zeros
|
|
49
|
-
cleanValue = Number(cleanValue).toString();
|
|
50
|
-
|
|
51
|
-
// We add enough leading zeros to fill the section
|
|
52
|
-
while (cleanValue.length < size) {
|
|
53
|
-
cleanValue = `0${cleanValue}`;
|
|
54
|
-
}
|
|
55
|
-
return cleanValue;
|
|
56
|
-
};
|
|
57
44
|
export const getLetterEditingOptions = (utils, sectionType, format) => {
|
|
58
45
|
switch (sectionType) {
|
|
59
46
|
case 'month':
|
|
@@ -75,42 +62,70 @@ export const getLetterEditingOptions = (utils, sectionType, format) => {
|
|
|
75
62
|
}
|
|
76
63
|
}
|
|
77
64
|
};
|
|
65
|
+
export const cleanDigitSectionValue = (utils, value, sectionType, format, hasLeadingZeros, sectionBoundaries) => {
|
|
66
|
+
const hasLetter = () => {
|
|
67
|
+
const startOfYear = utils.startOfYear(utils.date());
|
|
68
|
+
const startOfYearStr = utils.formatByString(startOfYear, format);
|
|
69
|
+
return Number.isNaN(Number(startOfYearStr));
|
|
70
|
+
};
|
|
71
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
72
|
+
if (sectionType !== 'day' && hasLetter()) {
|
|
73
|
+
throw new Error([`MUI: The token "${format}" is a digit format with letter in it.'
|
|
74
|
+
This type of format is only supported for 'day' sections`].join('\n'));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (sectionType === 'day' && hasLetter()) {
|
|
78
|
+
const date = utils.setDate(sectionBoundaries.longestMonth, value);
|
|
79
|
+
return utils.formatByString(date, format);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// queryValue without leading `0` (`01` => `1`)
|
|
83
|
+
const valueStr = value.toString();
|
|
84
|
+
if (hasLeadingZeros) {
|
|
85
|
+
const size = utils.formatByString(utils.date(), format).length;
|
|
86
|
+
let cleanValueStr = valueStr;
|
|
87
|
+
|
|
88
|
+
// Remove the leading zeros
|
|
89
|
+
cleanValueStr = Number(cleanValueStr).toString();
|
|
90
|
+
|
|
91
|
+
// Add enough leading zeros to fill the section
|
|
92
|
+
while (cleanValueStr.length < size) {
|
|
93
|
+
cleanValueStr = `0${cleanValueStr}`;
|
|
94
|
+
}
|
|
95
|
+
return cleanValueStr;
|
|
96
|
+
}
|
|
97
|
+
return valueStr;
|
|
98
|
+
};
|
|
78
99
|
export const adjustSectionValue = (utils, section, keyCode, sectionsValueBoundaries, activeDate) => {
|
|
79
100
|
const delta = getDeltaFromKeyCode(keyCode);
|
|
80
101
|
const isStart = keyCode === 'Home';
|
|
81
102
|
const isEnd = keyCode === 'End';
|
|
82
103
|
const shouldSetAbsolute = section.value === '' || isStart || isEnd;
|
|
83
|
-
const cleanDigitSectionValue = value => {
|
|
84
|
-
const valueStr = value.toString();
|
|
85
|
-
if (section.hasLeadingZeros) {
|
|
86
|
-
return cleanLeadingZerosInNumericSectionValue(utils, section.format, valueStr);
|
|
87
|
-
}
|
|
88
|
-
return valueStr;
|
|
89
|
-
};
|
|
90
104
|
const adjustDigitSection = () => {
|
|
91
105
|
const sectionBoundaries = sectionsValueBoundaries[section.type]({
|
|
92
106
|
currentDate: activeDate,
|
|
93
107
|
format: section.format,
|
|
94
108
|
contentType: section.contentType
|
|
95
109
|
});
|
|
110
|
+
const getCleanValue = value => cleanDigitSectionValue(utils, value, section.type, section.format, section.hasLeadingZeros, sectionBoundaries);
|
|
96
111
|
if (shouldSetAbsolute) {
|
|
97
112
|
if (section.type === 'year' && !isEnd && !isStart) {
|
|
98
113
|
return utils.formatByString(utils.date(), section.format);
|
|
99
114
|
}
|
|
100
115
|
if (delta > 0 || isStart) {
|
|
101
|
-
return
|
|
116
|
+
return getCleanValue(sectionBoundaries.minimum);
|
|
102
117
|
}
|
|
103
|
-
return
|
|
118
|
+
return getCleanValue(sectionBoundaries.maximum);
|
|
104
119
|
}
|
|
105
|
-
const currentSectionValue =
|
|
120
|
+
const currentSectionValue = parseInt(section.value, 10);
|
|
106
121
|
const newSectionValueNumber = currentSectionValue + delta;
|
|
107
122
|
if (newSectionValueNumber > sectionBoundaries.maximum) {
|
|
108
|
-
return
|
|
123
|
+
return getCleanValue(sectionBoundaries.minimum);
|
|
109
124
|
}
|
|
110
125
|
if (newSectionValueNumber < sectionBoundaries.minimum) {
|
|
111
|
-
return
|
|
126
|
+
return getCleanValue(sectionBoundaries.maximum);
|
|
112
127
|
}
|
|
113
|
-
return
|
|
128
|
+
return getCleanValue(newSectionValueNumber);
|
|
114
129
|
};
|
|
115
130
|
const adjustLetterSection = () => {
|
|
116
131
|
const options = getLetterEditingOptions(utils, section.type, section.format);
|
|
@@ -233,7 +248,7 @@ export const changeSectionValueFormat = (utils, valueStr, currentFormat, newForm
|
|
|
233
248
|
return utils.formatByString(utils.parse(valueStr, currentFormat), newFormat);
|
|
234
249
|
};
|
|
235
250
|
const isFourDigitYearFormat = (utils, format) => utils.formatByString(utils.date(), format).length === 4;
|
|
236
|
-
export const
|
|
251
|
+
export const doesSectionHaveLeadingZeros = (utils, contentType, sectionType, format) => {
|
|
237
252
|
if (contentType !== 'digit') {
|
|
238
253
|
return false;
|
|
239
254
|
}
|
|
@@ -307,13 +322,13 @@ export const splitFormatIntoSections = (utils, localeText, format, date) => {
|
|
|
307
322
|
return expandedToken;
|
|
308
323
|
}
|
|
309
324
|
const sectionConfig = getDateSectionConfigFromFormatToken(utils, token);
|
|
310
|
-
const sectionValue = date == null ? '' : utils.formatByString(date, token);
|
|
311
|
-
const
|
|
325
|
+
const sectionValue = date == null || !utils.isValid(date) ? '' : utils.formatByString(date, token);
|
|
326
|
+
const hasLeadingZeros = doesSectionHaveLeadingZeros(utils, sectionConfig.contentType, sectionConfig.type, token);
|
|
312
327
|
sections.push(_extends({}, sectionConfig, {
|
|
313
328
|
format: token,
|
|
314
329
|
value: sectionValue,
|
|
315
330
|
placeholder: getSectionPlaceholder(utils, localeText, sectionConfig, token),
|
|
316
|
-
hasLeadingZeros
|
|
331
|
+
hasLeadingZeros,
|
|
317
332
|
startSeparator: sections.length === 0 ? startSeparator : '',
|
|
318
333
|
endSeparator: '',
|
|
319
334
|
modified: false
|
|
@@ -406,10 +421,22 @@ export const createDateStrForInputFromSections = sections => {
|
|
|
406
421
|
export const getSectionsBoundaries = utils => {
|
|
407
422
|
const today = utils.date();
|
|
408
423
|
const endOfYear = utils.endOfYear(today);
|
|
409
|
-
const
|
|
424
|
+
const {
|
|
425
|
+
maxDaysInMonth,
|
|
426
|
+
longestMonth
|
|
427
|
+
} = utils.getMonthArray(today).reduce((acc, month) => {
|
|
410
428
|
const daysInMonth = utils.getDaysInMonth(month);
|
|
411
|
-
|
|
412
|
-
|
|
429
|
+
if (daysInMonth > acc.maxDaysInMonth) {
|
|
430
|
+
return {
|
|
431
|
+
maxDaysInMonth: daysInMonth,
|
|
432
|
+
longestMonth: month
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
return acc;
|
|
436
|
+
}, {
|
|
437
|
+
maxDaysInMonth: 0,
|
|
438
|
+
longestMonth: null
|
|
439
|
+
});
|
|
413
440
|
return {
|
|
414
441
|
year: ({
|
|
415
442
|
format
|
|
@@ -426,7 +453,8 @@ export const getSectionsBoundaries = utils => {
|
|
|
426
453
|
currentDate
|
|
427
454
|
}) => ({
|
|
428
455
|
minimum: 1,
|
|
429
|
-
maximum: currentDate != null && utils.isValid(currentDate) ? utils.getDaysInMonth(currentDate) : maxDaysInMonth
|
|
456
|
+
maximum: currentDate != null && utils.isValid(currentDate) ? utils.getDaysInMonth(currentDate) : maxDaysInMonth,
|
|
457
|
+
longestMonth: longestMonth
|
|
430
458
|
}),
|
|
431
459
|
weekDay: ({
|
|
432
460
|
format,
|
|
@@ -567,7 +595,7 @@ export const clampDaySection = (utils, sections, sectionsValueBoundaries) => {
|
|
|
567
595
|
contentType: section.contentType
|
|
568
596
|
});
|
|
569
597
|
return _extends({}, section, {
|
|
570
|
-
value:
|
|
598
|
+
value: cleanDigitSectionValue(utils, dayBoundaries.minimum, section.type, section.format, section.hasLeadingZeros, dayBoundaries)
|
|
571
599
|
});
|
|
572
600
|
});
|
|
573
601
|
const startOfMonth = getDateFromDateSections(utils, sectionsForStartOfMonth);
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
4
|
import { useUtils } from '../useUtils';
|
|
5
|
-
import { changeSectionValueFormat,
|
|
5
|
+
import { changeSectionValueFormat, cleanDigitSectionValue, doesSectionHaveLeadingZeros, getDateSectionConfigFromFormatToken, getDaysInWeekStr, getLetterEditingOptions } from './useField.utils';
|
|
6
6
|
const QUERY_LIFE_DURATION_MS = 5000;
|
|
7
7
|
const isQueryResponseWithoutValue = response => response.saveQuery != null;
|
|
8
8
|
|
|
@@ -137,7 +137,7 @@ export const useFieldCharacterEditing = ({
|
|
|
137
137
|
return applyQuery(params, getFirstSectionValueMatchingWithQuery);
|
|
138
138
|
};
|
|
139
139
|
const applyNumericEditing = params => {
|
|
140
|
-
const getNewSectionValue = (queryValue, sectionType, format,
|
|
140
|
+
const getNewSectionValue = (queryValue, sectionType, format, hasLeadingZeros, contentType) => {
|
|
141
141
|
const queryValueNumber = Number(`${queryValue}`);
|
|
142
142
|
const sectionBoundaries = sectionsValueBoundaries[sectionType]({
|
|
143
143
|
currentDate: null,
|
|
@@ -159,12 +159,7 @@ export const useFieldCharacterEditing = ({
|
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
161
|
const shouldGoToNextSection = Number(`${queryValue}0`) > sectionBoundaries.maximum || queryValue.length === sectionBoundaries.maximum.toString().length;
|
|
162
|
-
|
|
163
|
-
// queryValue without leading `0` (`01` => `1`)
|
|
164
|
-
let newSectionValue = queryValueNumber.toString();
|
|
165
|
-
if (hasTrailingZeroes) {
|
|
166
|
-
newSectionValue = cleanLeadingZerosInNumericSectionValue(utils, format, newSectionValue);
|
|
167
|
-
}
|
|
162
|
+
const newSectionValue = cleanDigitSectionValue(utils, queryValueNumber, sectionType, format, hasLeadingZeros, sectionBoundaries);
|
|
168
163
|
return {
|
|
169
164
|
sectionValue: newSectionValue,
|
|
170
165
|
shouldGoToNextSection
|
|
@@ -178,7 +173,7 @@ export const useFieldCharacterEditing = ({
|
|
|
178
173
|
// When editing a letter-format month and the user presses a digit,
|
|
179
174
|
// We can support the numeric editing by using the digit-format month and re-formatting the result.
|
|
180
175
|
if (activeSection.type === 'month') {
|
|
181
|
-
const response = getNewSectionValue(queryValue, activeSection.type, 'MM',
|
|
176
|
+
const response = getNewSectionValue(queryValue, activeSection.type, 'MM', doesSectionHaveLeadingZeros(utils, 'digit', 'month', 'MM'), 'digit');
|
|
182
177
|
if (isQueryResponseWithoutValue(response)) {
|
|
183
178
|
return response;
|
|
184
179
|
}
|
|
@@ -112,32 +112,38 @@ export const useFieldState = params => {
|
|
|
112
112
|
});
|
|
113
113
|
return addPositionPropertiesToSections(newSections);
|
|
114
114
|
};
|
|
115
|
-
const clearValue = () =>
|
|
116
|
-
value
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
const clearValue = () => {
|
|
116
|
+
if (valueManager.areValuesEqual(utils, state.value, valueManager.emptyValue)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
publishValue({
|
|
120
|
+
value: valueManager.emptyValue,
|
|
121
|
+
referenceValue: state.referenceValue
|
|
122
|
+
}, null);
|
|
123
|
+
};
|
|
119
124
|
const clearActiveSection = () => {
|
|
120
125
|
if (selectedSectionIndexes == null) {
|
|
121
|
-
return
|
|
126
|
+
return;
|
|
122
127
|
}
|
|
123
128
|
const activeSection = state.sections[selectedSectionIndexes.startIndex];
|
|
129
|
+
if (activeSection.value === '') {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
124
132
|
const activeDateManager = fieldValueManager.getActiveDateManager(utils, state, activeSection);
|
|
125
133
|
const activeDateSections = fieldValueManager.getActiveDateSections(state.sections, activeSection);
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
return section.value === '';
|
|
131
|
-
});
|
|
134
|
+
const nonEmptySectionCountBefore = activeDateSections.filter(section => section.value !== '').length;
|
|
135
|
+
const isTheOnlyNonEmptySection = nonEmptySectionCountBefore === 1;
|
|
132
136
|
const newSections = setSectionValue(selectedSectionIndexes.startIndex, '');
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
const newActiveDate = isTheOnlyNonEmptySection ? null : utils.date(new Date(''));
|
|
138
|
+
const newValue = activeDateManager.getNewValueFromNewActiveDate(newActiveDate);
|
|
139
|
+
if ((newActiveDate != null && !utils.isValid(newActiveDate)) !== (activeDateManager.activeDate != null && !utils.isValid(activeDateManager.activeDate))) {
|
|
140
|
+
publishValue(newValue, newSections);
|
|
141
|
+
} else {
|
|
142
|
+
setState(prevState => _extends({}, prevState, newValue, {
|
|
143
|
+
sections: newSections,
|
|
144
|
+
tempValueStrAndroid: null
|
|
145
|
+
}));
|
|
136
146
|
}
|
|
137
|
-
return setState(prevState => _extends({}, prevState, {
|
|
138
|
-
sections: newSections,
|
|
139
|
-
tempValueStrAndroid: null
|
|
140
|
-
}, newValue));
|
|
141
147
|
};
|
|
142
148
|
const updateValueFromValueStr = valueStr => {
|
|
143
149
|
const parseDateStr = (dateStr, referenceDate) => {
|
|
@@ -161,9 +167,9 @@ export const useFieldState = params => {
|
|
|
161
167
|
shouldGoToNextSection
|
|
162
168
|
}) => {
|
|
163
169
|
const commit = ({
|
|
164
|
-
shouldPublish,
|
|
165
170
|
values,
|
|
166
|
-
sections
|
|
171
|
+
sections,
|
|
172
|
+
shouldPublish
|
|
167
173
|
}) => {
|
|
168
174
|
if (shouldGoToNextSection && selectedSectionIndexes && selectedSectionIndexes.startIndex < state.sections.length - 1) {
|
|
169
175
|
setSelectedSections(selectedSectionIndexes.startIndex + 1);
|
|
@@ -171,38 +177,38 @@ export const useFieldState = params => {
|
|
|
171
177
|
setSelectedSections(selectedSectionIndexes.startIndex);
|
|
172
178
|
}
|
|
173
179
|
if (shouldPublish) {
|
|
174
|
-
|
|
180
|
+
publishValue(values, sections);
|
|
181
|
+
} else {
|
|
182
|
+
setState(prevState => _extends({}, prevState, values, {
|
|
183
|
+
sections: sections ?? state.sections,
|
|
184
|
+
tempValueStrAndroid: null
|
|
185
|
+
}));
|
|
175
186
|
}
|
|
176
|
-
return setState(prev => _extends({}, prev, {
|
|
177
|
-
tempValueStrAndroid: null
|
|
178
|
-
}, values, {
|
|
179
|
-
sections: sections ?? prev.sections
|
|
180
|
-
}));
|
|
181
187
|
};
|
|
182
188
|
const activeDateManager = fieldValueManager.getActiveDateManager(utils, state, activeSection);
|
|
183
189
|
const newSections = setSectionValue(selectedSectionIndexes.startIndex, newSectionValue);
|
|
184
190
|
const activeDateSections = fieldValueManager.getActiveDateSections(newSections, activeSection);
|
|
185
|
-
let
|
|
191
|
+
let newActiveDate = getDateFromDateSections(utils, activeDateSections);
|
|
186
192
|
|
|
187
193
|
// When all the sections are filled but the date is invalid, it can be because the month has fewer days than asked.
|
|
188
194
|
// We can try to set the day to the maximum boundary.
|
|
189
|
-
if (!utils.isValid(
|
|
195
|
+
if (!utils.isValid(newActiveDate) && activeDateSections.every(section => section.type === 'weekDay' || section.value !== '') && activeDateSections.some(section => section.type === 'day')) {
|
|
190
196
|
const cleanSections = clampDaySection(utils, activeDateSections, sectionsValueBoundaries);
|
|
191
197
|
if (cleanSections != null) {
|
|
192
|
-
|
|
198
|
+
newActiveDate = getDateFromDateSections(utils, cleanSections);
|
|
193
199
|
}
|
|
194
200
|
}
|
|
195
|
-
if (
|
|
196
|
-
const mergedDate = mergeDateIntoReferenceDate(utils,
|
|
201
|
+
if (newActiveDate != null && utils.isValid(newActiveDate)) {
|
|
202
|
+
const mergedDate = mergeDateIntoReferenceDate(utils, newActiveDate, activeDateSections, activeDateManager.referenceActiveDate, true);
|
|
197
203
|
return commit({
|
|
198
|
-
|
|
199
|
-
|
|
204
|
+
values: activeDateManager.getNewValueFromNewActiveDate(mergedDate),
|
|
205
|
+
shouldPublish: true
|
|
200
206
|
});
|
|
201
207
|
}
|
|
202
208
|
return commit({
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
209
|
+
values: activeDateManager.getNewValueFromNewActiveDate(newActiveDate),
|
|
210
|
+
sections: newSections,
|
|
211
|
+
shouldPublish: (newActiveDate != null && !utils.isValid(newActiveDate)) !== (activeDateManager.activeDate != null && !utils.isValid(activeDateManager.activeDate))
|
|
206
212
|
});
|
|
207
213
|
};
|
|
208
214
|
const setTempAndroidValueStr = tempValueStrAndroid => setState(prev => _extends({}, prev, {
|
|
@@ -220,7 +226,7 @@ export const useFieldState = params => {
|
|
|
220
226
|
}, [valueFromTheOutside]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
221
227
|
|
|
222
228
|
React.useEffect(() => {
|
|
223
|
-
const sections = fieldValueManager.getSectionsFromValue(utils, localeText,
|
|
229
|
+
const sections = fieldValueManager.getSectionsFromValue(utils, localeText, null, state.value, format);
|
|
224
230
|
validateSections(sections, valueType);
|
|
225
231
|
setState(prevState => _extends({}, prevState, {
|
|
226
232
|
sections,
|
|
@@ -10,18 +10,22 @@ export const singleItemValueManager = {
|
|
|
10
10
|
};
|
|
11
11
|
export const singleItemFieldValueManager = {
|
|
12
12
|
updateReferenceValue: (utils, value, prevReferenceValue) => value == null || !utils.isValid(value) ? prevReferenceValue : value,
|
|
13
|
-
getSectionsFromValue: (utils, localeText, prevSections, date, format) =>
|
|
13
|
+
getSectionsFromValue: (utils, localeText, prevSections, date, format) => {
|
|
14
|
+
const shouldReUsePrevDateSections = !utils.isValid(date) && !!prevSections;
|
|
15
|
+
if (shouldReUsePrevDateSections) {
|
|
16
|
+
return prevSections;
|
|
17
|
+
}
|
|
18
|
+
return addPositionPropertiesToSections(splitFormatIntoSections(utils, localeText, format, date));
|
|
19
|
+
},
|
|
14
20
|
getValueStrFromSections: sections => createDateStrForInputFromSections(sections),
|
|
15
21
|
getActiveDateSections: sections => sections,
|
|
16
22
|
getActiveDateManager: (utils, state) => ({
|
|
17
23
|
activeDate: state.value,
|
|
18
24
|
referenceActiveDate: state.referenceValue,
|
|
19
|
-
getNewValueFromNewActiveDate: newActiveDate => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
+
getNewValueFromNewActiveDate: newActiveDate => ({
|
|
26
|
+
value: newActiveDate,
|
|
27
|
+
referenceValue: newActiveDate == null || !utils.isValid(newActiveDate) ? state.referenceValue : newActiveDate
|
|
28
|
+
})
|
|
25
29
|
}),
|
|
26
30
|
parseValueStr: (valueStr, referenceValue, parseDate) => parseDate(valueStr.trim(), referenceValue),
|
|
27
31
|
hasError: error => error != null,
|
package/modern/locales/deDE.js
CHANGED
|
@@ -33,11 +33,10 @@ const deDEPickers = {
|
|
|
33
33
|
minutesClockNumberText: minutes => `${minutes} ${timeViews.minutes}`,
|
|
34
34
|
secondsClockNumberText: seconds => `${seconds} ${timeViews.seconds}`,
|
|
35
35
|
// Calendar labels
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
calendarWeekNumberHeaderLabel: 'Kalenderwoche',
|
|
37
|
+
calendarWeekNumberHeaderText: '#',
|
|
38
|
+
calendarWeekNumberAriaLabelText: weekNumber => `Woche ${weekNumber}`,
|
|
39
|
+
calendarWeekNumberText: weekNumber => `${weekNumber}`,
|
|
41
40
|
// Open picker labels
|
|
42
41
|
openDatePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `Datum auswählen, gewähltes Datum ist ${utils.format(value, 'fullDate')}` : 'Datum auswählen',
|
|
43
42
|
openTimePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `Uhrzeit auswählen, gewählte Uhrzeit ist ${utils.format(value, 'fullTime')}` : 'Uhrzeit auswählen',
|
package/modern/locales/frFR.js
CHANGED
|
@@ -31,27 +31,24 @@ const frFRPickers = {
|
|
|
31
31
|
minutesClockNumberText: minutes => `${minutes} minutes`,
|
|
32
32
|
secondsClockNumberText: seconds => `${seconds} secondes`,
|
|
33
33
|
// Calendar labels
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
calendarWeekNumberHeaderLabel: 'Semaine',
|
|
35
|
+
calendarWeekNumberHeaderText: '#',
|
|
36
|
+
calendarWeekNumberAriaLabelText: weekNumber => `Semaine ${weekNumber}`,
|
|
37
|
+
calendarWeekNumberText: weekNumber => `${weekNumber}`,
|
|
39
38
|
// Open picker labels
|
|
40
39
|
openDatePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `Choisir la date, la date sélectionnée est ${utils.format(value, 'fullDate')}` : 'Choisir la date',
|
|
41
40
|
openTimePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `Choisir l'heure, l'heure sélectionnée est ${utils.format(value, 'fullTime')}` : "Choisir l'heure",
|
|
42
41
|
// Table labels
|
|
43
42
|
timeTableLabel: "choix de l'heure",
|
|
44
|
-
dateTableLabel: 'choix de la date'
|
|
45
|
-
|
|
43
|
+
dateTableLabel: 'choix de la date',
|
|
46
44
|
// Field section placeholders
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
fieldYearPlaceholder: params => 'A'.repeat(params.digitAmount),
|
|
46
|
+
fieldMonthPlaceholder: params => params.contentType === 'letter' ? 'MMMM' : 'MM',
|
|
47
|
+
fieldDayPlaceholder: () => 'JJ',
|
|
50
48
|
// fieldWeekDayPlaceholder: params => params.contentType === 'letter' ? 'EEEE' : 'EE',
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
fieldHoursPlaceholder: () => 'hh',
|
|
50
|
+
fieldMinutesPlaceholder: () => 'mm',
|
|
51
|
+
fieldSecondsPlaceholder: () => 'ss',
|
|
52
|
+
fieldMeridiemPlaceholder: () => 'aa'
|
|
55
53
|
};
|
|
56
|
-
|
|
57
54
|
export const frFR = getPickersLocalization(frFRPickers);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getPickersLocalization } from './utils/getPickersLocalization';
|
|
2
|
+
const views = {
|
|
3
|
+
hours: 'שעות',
|
|
4
|
+
minutes: 'דקות',
|
|
5
|
+
seconds: 'שניות'
|
|
6
|
+
};
|
|
7
|
+
const heILPickers = {
|
|
8
|
+
// Calendar navigation
|
|
9
|
+
previousMonth: 'חודש קודם',
|
|
10
|
+
nextMonth: 'חודש הבא',
|
|
11
|
+
// View navigation
|
|
12
|
+
openPreviousView: 'תצוגה קודמת',
|
|
13
|
+
openNextView: 'תצוגה הבאה',
|
|
14
|
+
calendarViewSwitchingButtonAriaLabel: view => view === 'year' ? 'תצוגת שנה פתוחה, מעבר לתצוגת לוח שנה' : 'תצוגת לוח שנה פתוחה, מעבר לתצוגת שנה',
|
|
15
|
+
// DateRange placeholders
|
|
16
|
+
start: 'תחילה',
|
|
17
|
+
end: 'סיום',
|
|
18
|
+
// Action bar
|
|
19
|
+
cancelButtonLabel: 'ביטול',
|
|
20
|
+
clearButtonLabel: 'ניקוי',
|
|
21
|
+
okButtonLabel: 'אישור',
|
|
22
|
+
todayButtonLabel: 'היום',
|
|
23
|
+
// Toolbar titles
|
|
24
|
+
datePickerToolbarTitle: 'בחירת תאריך',
|
|
25
|
+
dateTimePickerToolbarTitle: 'בחירת תאריך ושעה',
|
|
26
|
+
timePickerToolbarTitle: 'בחירת שעה',
|
|
27
|
+
dateRangePickerToolbarTitle: 'בחירת טווח תאריכים',
|
|
28
|
+
// Clock labels
|
|
29
|
+
clockLabelText: (view, time, adapter) => `בחירת ${views[view]}. ${time === null ? 'לא נבחרה שעה' : `השעה הנבחרת היא ${adapter.format(time, 'fullTime')}`}`,
|
|
30
|
+
hoursClockNumberText: hours => `${hours} שעות`,
|
|
31
|
+
minutesClockNumberText: minutes => `${minutes} דקות`,
|
|
32
|
+
secondsClockNumberText: seconds => `${seconds} שניות`,
|
|
33
|
+
// Calendar labels
|
|
34
|
+
// calendarWeekNumberHeaderLabel: 'Week number',
|
|
35
|
+
// calendarWeekNumberHeaderText: '#',
|
|
36
|
+
// calendarWeekNumberAriaLabelText: weekNumber => `Week ${weekNumber}`,
|
|
37
|
+
// calendarWeekNumberText: weekNumber => `${weekNumber}`,
|
|
38
|
+
|
|
39
|
+
// Open picker labels
|
|
40
|
+
openDatePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `בחירת תאריך, התאריך שנבחר הוא ${utils.format(value, 'fullDate')}` : 'בחירת תאריך',
|
|
41
|
+
openTimePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `בחירת שעה, השעה שנבחרה היא ${utils.format(value, 'fullTime')}` : 'בחירת שעה',
|
|
42
|
+
// Table labels
|
|
43
|
+
timeTableLabel: 'בחירת שעה',
|
|
44
|
+
dateTableLabel: 'בחירת תאריך'
|
|
45
|
+
|
|
46
|
+
// Field section placeholders
|
|
47
|
+
// fieldYearPlaceholder: params => 'Y'.repeat(params.digitAmount),
|
|
48
|
+
// fieldMonthPlaceholder: params => params.contentType === 'letter' ? 'MMMM' : 'MM',
|
|
49
|
+
// fieldDayPlaceholder: () => 'DD',
|
|
50
|
+
// fieldWeekDayPlaceholder: params => params.contentType === 'letter' ? 'EEEE' : 'EE',
|
|
51
|
+
// fieldHoursPlaceholder: () => 'hh',
|
|
52
|
+
// fieldMinutesPlaceholder: () => 'mm',
|
|
53
|
+
// fieldSecondsPlaceholder: () => 'ss',
|
|
54
|
+
// fieldMeridiemPlaceholder: () => 'aa',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const heIL = getPickersLocalization(heILPickers);
|
package/modern/locales/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import { expect } from 'chai';
|
|
5
5
|
import { spy } from 'sinon';
|
|
6
6
|
import { screen, userEvent } from '@mui/monorepo/test/utils';
|
|
7
|
-
import { openPicker } from 'test/utils/pickers-utils';
|
|
7
|
+
import { getTextbox, openPicker } from 'test/utils/pickers-utils';
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
export const testPickerOpenCloseLifeCycle = (ElementToTest, getOptions) => {
|
|
10
10
|
const _getOptions = getOptions(),
|
|
@@ -87,6 +87,25 @@ export const testPickerOpenCloseLifeCycle = (ElementToTest, getOptions) => {
|
|
|
87
87
|
expect(onAccept.callCount).to.equal(pickerParams.variant === 'mobile' ? 0 : 1);
|
|
88
88
|
expect(onClose.callCount).to.equal(pickerParams.variant === 'mobile' ? 0 : 1);
|
|
89
89
|
});
|
|
90
|
+
it('should not select any field section after closing on mobile', () => {
|
|
91
|
+
if (pickerParams.variant !== 'mobile') {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
95
|
+
defaultValue: values[0]
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
// Change the value
|
|
99
|
+
setNewValue(values[0]);
|
|
100
|
+
let textbox;
|
|
101
|
+
if (pickerParams.type === 'date-range') {
|
|
102
|
+
textbox = screen.getAllByRole('textbox')[0];
|
|
103
|
+
} else {
|
|
104
|
+
textbox = getTextbox();
|
|
105
|
+
}
|
|
106
|
+
expect(textbox.selectionStart).to.be.equal(0);
|
|
107
|
+
expect(textbox.selectionEnd).to.be.equal(0);
|
|
108
|
+
});
|
|
90
109
|
it('should call onChange, onClose and onAccept when selecting a value and `props.closeOnSelect` is true', () => {
|
|
91
110
|
const onChange = spy();
|
|
92
111
|
const onAccept = spy();
|
package/node/index.js
CHANGED
|
@@ -102,7 +102,7 @@ const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function PickersArrow
|
|
|
102
102
|
elementType: PreviousIconButton,
|
|
103
103
|
externalSlotProps: slotProps?.previousIconButton ?? componentsProps?.previousIconButton,
|
|
104
104
|
additionalProps: {
|
|
105
|
-
size: '
|
|
105
|
+
size: 'medium',
|
|
106
106
|
title: leftProps.label,
|
|
107
107
|
'aria-label': leftProps.label,
|
|
108
108
|
disabled: leftProps.isDisabled,
|
|
@@ -119,7 +119,7 @@ const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function PickersArrow
|
|
|
119
119
|
elementType: NextIconButton,
|
|
120
120
|
externalSlotProps: slotProps?.nextIconButton ?? componentsProps?.nextIconButton,
|
|
121
121
|
additionalProps: {
|
|
122
|
-
size: '
|
|
122
|
+
size: 'medium',
|
|
123
123
|
title: rightProps.label,
|
|
124
124
|
'aria-label': rightProps.label,
|
|
125
125
|
disabled: rightProps.isDisabled,
|
|
@@ -136,6 +136,9 @@ const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function PickersArrow
|
|
|
136
136
|
const _useSlotProps = (0, _utils2.useSlotProps)({
|
|
137
137
|
elementType: LeftArrowIcon,
|
|
138
138
|
externalSlotProps: slotProps?.leftArrowIcon ?? componentsProps?.leftArrowIcon,
|
|
139
|
+
additionalProps: {
|
|
140
|
+
fontSize: 'inherit'
|
|
141
|
+
},
|
|
139
142
|
ownerState: undefined
|
|
140
143
|
}),
|
|
141
144
|
leftArrowIconProps = (0, _objectWithoutPropertiesLoose2.default)(_useSlotProps, _excluded2);
|
|
@@ -144,6 +147,9 @@ const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function PickersArrow
|
|
|
144
147
|
const _useSlotProps2 = (0, _utils2.useSlotProps)({
|
|
145
148
|
elementType: RightArrowIcon,
|
|
146
149
|
externalSlotProps: slotProps?.rightArrowIcon ?? componentsProps?.rightArrowIcon,
|
|
150
|
+
additionalProps: {
|
|
151
|
+
fontSize: 'inherit'
|
|
152
|
+
},
|
|
147
153
|
ownerState: undefined
|
|
148
154
|
}),
|
|
149
155
|
rightArrowIconProps = (0, _objectWithoutPropertiesLoose2.default)(_useSlotProps2, _excluded3);
|