@mui/x-date-pickers 7.19.0 → 7.21.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.
- package/AdapterDayjs/AdapterDayjs.js +2 -0
- package/CHANGELOG.md +224 -43
- package/DateCalendar/DateCalendar.js +1 -1
- package/DateCalendar/DateCalendar.types.d.ts +1 -1
- package/DateField/DateField.types.d.ts +2 -7
- package/DateField/index.d.ts +1 -1
- package/DatePicker/DatePicker.js +1 -1
- package/DatePicker/DatePicker.types.d.ts +8 -1
- package/DatePicker/index.d.ts +1 -1
- package/DateTimeField/DateTimeField.types.d.ts +2 -7
- package/DateTimeField/index.d.ts +1 -1
- package/DateTimePicker/DateTimePicker.js +1 -1
- package/DateTimePicker/DateTimePicker.types.d.ts +9 -1
- package/DateTimePicker/DateTimePickerTabs.js +1 -1
- package/DateTimePicker/index.d.ts +1 -1
- package/DesktopDatePicker/DesktopDatePicker.js +1 -1
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
- package/DigitalClock/DigitalClock.js +33 -0
- package/MobileDatePicker/MobileDatePicker.js +1 -1
- package/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +32 -1
- package/PickersSectionList/PickersSectionList.d.ts +9 -0
- package/PickersSectionList/PickersSectionList.js +30 -9
- package/StaticDatePicker/StaticDatePicker.js +1 -1
- package/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/TimeClock/Clock.js +8 -0
- package/TimeField/TimeField.types.d.ts +2 -7
- package/TimeField/index.d.ts +1 -1
- package/TimePicker/TimePicker.types.d.ts +9 -1
- package/TimePicker/index.d.ts +1 -1
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +3 -1
- package/hooks/useParsedFormat.d.ts +15 -0
- package/hooks/useParsedFormat.js +43 -0
- package/hooks/usePickersContext.d.ts +4 -0
- package/hooks/usePickersContext.js +15 -0
- package/index.js +1 -1
- package/internals/components/PickersProvider.d.ts +34 -0
- package/internals/components/PickersProvider.js +26 -0
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -10
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +2 -5
- package/internals/hooks/useField/buildSectionsFromFormat.d.ts +1 -2
- package/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
- package/internals/hooks/useField/useField.js +1 -1
- package/internals/hooks/useField/useField.utils.d.ts +3 -3
- package/internals/hooks/useField/useField.utils.js +13 -13
- package/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/internals/hooks/useField/useFieldState.js +3 -5
- package/internals/hooks/useMobilePicker/useMobilePicker.js +7 -4
- package/internals/hooks/usePicker/usePicker.js +10 -1
- package/internals/hooks/usePicker/usePicker.types.d.ts +2 -1
- package/internals/hooks/usePicker/usePickerOwnerState.d.ts +9 -0
- package/internals/hooks/usePicker/usePickerOwnerState.js +13 -0
- package/internals/hooks/usePicker/usePickerValue.js +7 -2
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +2 -0
- package/internals/index.d.ts +1 -0
- package/internals/index.js +1 -0
- package/internals/utils/utils.d.ts +7 -0
- package/internals/utils/utils.js +11 -0
- package/models/pickers.d.ts +19 -1
- package/modern/AdapterDayjs/AdapterDayjs.js +2 -0
- package/modern/DateCalendar/DateCalendar.js +1 -1
- package/modern/DatePicker/DatePicker.js +1 -1
- package/modern/DateTimePicker/DateTimePicker.js +1 -1
- package/modern/DateTimePicker/DateTimePickerTabs.js +1 -1
- package/modern/DesktopDatePicker/DesktopDatePicker.js +1 -1
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
- package/modern/DigitalClock/DigitalClock.js +33 -0
- package/modern/MobileDatePicker/MobileDatePicker.js +1 -1
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +32 -1
- package/modern/PickersSectionList/PickersSectionList.js +30 -9
- package/modern/StaticDatePicker/StaticDatePicker.js +1 -1
- package/modern/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/modern/TimeClock/Clock.js +8 -0
- package/modern/hooks/index.js +3 -1
- package/modern/hooks/useParsedFormat.js +43 -0
- package/modern/hooks/usePickersContext.js +15 -0
- package/modern/index.js +1 -1
- package/modern/internals/components/PickersProvider.js +26 -0
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -10
- package/modern/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
- package/modern/internals/hooks/useField/useField.js +1 -1
- package/modern/internals/hooks/useField/useField.utils.js +13 -13
- package/modern/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/modern/internals/hooks/useField/useFieldState.js +3 -5
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +7 -4
- package/modern/internals/hooks/usePicker/usePicker.js +10 -1
- package/modern/internals/hooks/usePicker/usePickerOwnerState.js +13 -0
- package/modern/internals/hooks/usePicker/usePickerValue.js +7 -2
- package/modern/internals/index.js +1 -0
- package/modern/internals/utils/utils.js +11 -0
- package/node/AdapterDayjs/AdapterDayjs.js +2 -0
- package/node/DateCalendar/DateCalendar.js +1 -1
- package/node/DatePicker/DatePicker.js +1 -1
- package/node/DateTimePicker/DateTimePicker.js +1 -1
- package/node/DateTimePicker/DateTimePickerTabs.js +1 -1
- package/node/DesktopDatePicker/DesktopDatePicker.js +1 -1
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
- package/node/DigitalClock/DigitalClock.js +33 -0
- package/node/MobileDatePicker/MobileDatePicker.js +1 -1
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +32 -1
- package/node/PickersSectionList/PickersSectionList.js +30 -9
- package/node/StaticDatePicker/StaticDatePicker.js +1 -1
- package/node/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/node/TimeClock/Clock.js +8 -0
- package/node/hooks/index.js +15 -1
- package/node/hooks/useParsedFormat.js +50 -0
- package/node/hooks/usePickersContext.js +21 -0
- package/node/index.js +1 -1
- package/node/internals/components/PickersProvider.js +34 -0
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +7 -9
- package/node/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
- package/node/internals/hooks/useField/useField.js +1 -1
- package/node/internals/hooks/useField/useField.utils.js +13 -13
- package/node/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/node/internals/hooks/useField/useFieldState.js +3 -5
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +5 -3
- package/node/internals/hooks/usePicker/usePicker.js +10 -1
- package/node/internals/hooks/usePicker/usePickerOwnerState.js +20 -0
- package/node/internals/hooks/usePicker/usePickerValue.js +7 -1
- package/node/internals/index.js +7 -0
- package/node/internals/utils/utils.js +13 -1
- package/package.json +4 -4
|
@@ -6,7 +6,7 @@ import { SlotComponentProps } from '@mui/utils';
|
|
|
6
6
|
import { BaseNonStaticPickerProps, BasePickerProps, BaseNonRangeNonStaticPickerProps } from '../../models/props/basePickerProps';
|
|
7
7
|
import { PickersPopperSlots, PickersPopperSlotProps } from '../../components/PickersPopper';
|
|
8
8
|
import { UsePickerParams, UsePickerProps } from '../usePicker';
|
|
9
|
-
import { BaseSingleInputFieldProps, FieldSection, PickerValidDate } from '../../../models';
|
|
9
|
+
import { BaseSingleInputFieldProps, FieldSection, PickerOwnerState, PickerValidDate } from '../../../models';
|
|
10
10
|
import { ExportedPickersLayoutSlots, ExportedPickersLayoutSlotProps, PickersLayoutSlotProps } from '../../../PickersLayout/PickersLayout.types';
|
|
11
11
|
import { UsePickerValueNonStaticProps } from '../usePicker/usePickerValue.types';
|
|
12
12
|
import { UsePickerViewsNonStaticProps, UsePickerViewsProps } from '../usePicker/usePickerViews';
|
|
@@ -40,15 +40,12 @@ export interface UseDesktopPickerSlots<TDate extends PickerValidDate, TView exte
|
|
|
40
40
|
}
|
|
41
41
|
export interface UseDesktopPickerSlotProps<TDate extends PickerValidDate, TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean> extends ExportedUseDesktopPickerSlotProps<TDate, TView, TEnableAccessibleFieldDOMStructure>, Pick<PickersLayoutSlotProps<TDate | null, TDate, TView>, 'toolbar'> {
|
|
42
42
|
}
|
|
43
|
-
export interface UseDesktopPickerOwnerState {
|
|
44
|
-
open: boolean;
|
|
45
|
-
}
|
|
46
43
|
export interface ExportedUseDesktopPickerSlotProps<TDate extends PickerValidDate, TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean> extends PickersPopperSlotProps, ExportedPickersLayoutSlotProps<TDate | null, TDate, TView>, UseClearableFieldSlotProps {
|
|
47
44
|
field?: SlotComponentPropsFromProps<BaseSingleInputFieldProps<TDate | null, TDate, FieldSection, TEnableAccessibleFieldDOMStructure, unknown>, {}, UsePickerProps<TDate | null, TDate, any, any, any, any>>;
|
|
48
45
|
textField?: SlotComponentProps<typeof TextField, {}, Record<string, any>>;
|
|
49
46
|
inputAdornment?: Partial<InputAdornmentProps>;
|
|
50
47
|
openPickerButton?: SlotComponentProps<typeof IconButton, {}, UseDesktopPickerProps<TDate, any, TEnableAccessibleFieldDOMStructure, any, any>>;
|
|
51
|
-
openPickerIcon?: SlotComponentPropsFromProps<Record<string, any>, {},
|
|
48
|
+
openPickerIcon?: SlotComponentPropsFromProps<Record<string, any>, {}, PickerOwnerState<TDate | null>>;
|
|
52
49
|
}
|
|
53
50
|
export interface DesktopOnlyPickerProps extends BaseNonStaticPickerProps, BaseNonRangeNonStaticPickerProps, UsePickerValueNonStaticProps, UsePickerViewsNonStaticProps {
|
|
54
51
|
/**
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { FieldSection, MuiPickersAdapter,
|
|
1
|
+
import { FieldSection, MuiPickersAdapter, PickerValidDate } from '../../../models';
|
|
2
2
|
import { PickersLocaleText } from '../../../locales';
|
|
3
3
|
interface BuildSectionsFromFormatParams<TDate extends PickerValidDate> {
|
|
4
4
|
utils: MuiPickersAdapter<TDate>;
|
|
5
5
|
format: string;
|
|
6
6
|
formatDensity: 'dense' | 'spacious';
|
|
7
7
|
isRtl: boolean;
|
|
8
|
-
timezone: PickersTimezone;
|
|
9
8
|
shouldRespectLeadingZeros: boolean;
|
|
10
9
|
localeText: PickersLocaleText<TDate>;
|
|
11
10
|
localizedDigits: string[];
|
|
@@ -38,12 +38,12 @@ const getEscapedPartsFromFormat = ({
|
|
|
38
38
|
}
|
|
39
39
|
return escapedParts;
|
|
40
40
|
};
|
|
41
|
-
const getSectionPlaceholder = (utils,
|
|
41
|
+
const getSectionPlaceholder = (utils, localeText, sectionConfig, sectionFormat) => {
|
|
42
42
|
switch (sectionConfig.type) {
|
|
43
43
|
case 'year':
|
|
44
44
|
{
|
|
45
45
|
return localeText.fieldYearPlaceholder({
|
|
46
|
-
digitAmount: utils.formatByString(utils.date(undefined,
|
|
46
|
+
digitAmount: utils.formatByString(utils.date(undefined, 'default'), sectionFormat).length,
|
|
47
47
|
format: sectionFormat
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -99,7 +99,6 @@ const getSectionPlaceholder = (utils, timezone, localeText, sectionConfig, secti
|
|
|
99
99
|
};
|
|
100
100
|
const createSection = ({
|
|
101
101
|
utils,
|
|
102
|
-
timezone,
|
|
103
102
|
date,
|
|
104
103
|
shouldRespectLeadingZeros,
|
|
105
104
|
localeText,
|
|
@@ -112,7 +111,7 @@ const createSection = ({
|
|
|
112
111
|
throw new Error('MUI X: Should not call `commitToken` with an empty token');
|
|
113
112
|
}
|
|
114
113
|
const sectionConfig = getDateSectionConfigFromFormatToken(utils, token);
|
|
115
|
-
const hasLeadingZerosInFormat = doesSectionFormatHaveLeadingZeros(utils,
|
|
114
|
+
const hasLeadingZerosInFormat = doesSectionFormatHaveLeadingZeros(utils, sectionConfig.contentType, sectionConfig.type, token);
|
|
116
115
|
const hasLeadingZerosInInput = shouldRespectLeadingZeros ? hasLeadingZerosInFormat : sectionConfig.contentType === 'digit';
|
|
117
116
|
const isValidDate = date != null && utils.isValid(date);
|
|
118
117
|
let sectionValue = isValidDate ? utils.formatByString(date, token) : '';
|
|
@@ -134,7 +133,7 @@ const createSection = ({
|
|
|
134
133
|
format: token,
|
|
135
134
|
maxLength,
|
|
136
135
|
value: sectionValue,
|
|
137
|
-
placeholder: getSectionPlaceholder(utils,
|
|
136
|
+
placeholder: getSectionPlaceholder(utils, localeText, sectionConfig, token),
|
|
138
137
|
hasLeadingZerosInFormat,
|
|
139
138
|
hasLeadingZerosInInput,
|
|
140
139
|
startSeparator,
|
|
@@ -75,7 +75,7 @@ export const useField = params => {
|
|
|
75
75
|
// eslint-disable-next-line default-case
|
|
76
76
|
switch (true) {
|
|
77
77
|
// Select all
|
|
78
|
-
case (event.ctrlKey || event.metaKey) && event.
|
|
78
|
+
case (event.ctrlKey || event.metaKey) && String.fromCharCode(event.keyCode) === 'A' && !event.shiftKey && !event.altKey:
|
|
79
79
|
{
|
|
80
80
|
// prevent default to make sure that the next line "select all" while updating
|
|
81
81
|
// the internal state at the same time.
|
|
@@ -3,7 +3,7 @@ import { FieldSectionType, FieldValueType, FieldSection, MuiPickersAdapter, Fiel
|
|
|
3
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
|
-
export declare const getDaysInWeekStr: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>,
|
|
6
|
+
export declare const getDaysInWeekStr: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, format: string) => string[];
|
|
7
7
|
export declare const getLetterEditingOptions: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, timezone: PickersTimezone, sectionType: FieldSectionType, format: string) => string[];
|
|
8
8
|
export declare const FORMAT_SECONDS_NO_LEADING_ZEROS = "s";
|
|
9
9
|
export declare const getLocalizedDigits: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>) => string[];
|
|
@@ -22,7 +22,7 @@ export declare const adjustSectionValue: <TDate extends PickerValidDate, TSectio
|
|
|
22
22
|
}) => string;
|
|
23
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
|
-
export declare const doesSectionFormatHaveLeadingZeros: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>,
|
|
25
|
+
export declare const doesSectionFormatHaveLeadingZeros: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, contentType: FieldSectionContentType, sectionType: FieldSectionType, format: string) => boolean;
|
|
26
26
|
/**
|
|
27
27
|
* Some date libraries like `dayjs` don't support parsing from date with escaped characters.
|
|
28
28
|
* To make sure that the parsing works, we are building a format and a date without any separator.
|
|
@@ -32,7 +32,7 @@ export declare const createDateStrForV7HiddenInputFromSections: (sections: Field
|
|
|
32
32
|
export declare const createDateStrForV6InputFromSections: (sections: FieldSection[], localizedDigits: string[], isRtl: boolean) => string;
|
|
33
33
|
export declare const getSectionsBoundaries: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, localizedDigits: string[], timezone: PickersTimezone) => FieldSectionsValueBoundaries<TDate>;
|
|
34
34
|
export declare const validateSections: <TSection extends FieldSection>(sections: TSection[], valueType: FieldValueType) => void;
|
|
35
|
-
export declare const mergeDateIntoReferenceDate: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>,
|
|
35
|
+
export declare const mergeDateIntoReferenceDate: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, dateToTransferFrom: TDate, sections: FieldSection[], referenceDate: TDate, shouldLimitToEditedSections: boolean) => TDate;
|
|
36
36
|
export declare const isAndroid: () => boolean;
|
|
37
37
|
export declare const getSectionOrder: (sections: FieldSection[], shouldApplyRTL: boolean) => SectionOrdering;
|
|
38
38
|
export declare const parseSelectedSections: (selectedSections: FieldSelectedSections, sections: FieldSection[]) => FieldParsedSelectedSections;
|
|
@@ -31,9 +31,9 @@ const getDeltaFromKeyCode = keyCode => {
|
|
|
31
31
|
return 0;
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
export const getDaysInWeekStr = (utils,
|
|
34
|
+
export const getDaysInWeekStr = (utils, format) => {
|
|
35
35
|
const elements = [];
|
|
36
|
-
const now = utils.date(undefined,
|
|
36
|
+
const now = utils.date(undefined, 'default');
|
|
37
37
|
const startDate = utils.startOfWeek(now);
|
|
38
38
|
const endDate = utils.endOfWeek(now);
|
|
39
39
|
let current = startDate;
|
|
@@ -51,7 +51,7 @@ export const getLetterEditingOptions = (utils, timezone, sectionType, format) =>
|
|
|
51
51
|
}
|
|
52
52
|
case 'weekDay':
|
|
53
53
|
{
|
|
54
|
-
return getDaysInWeekStr(utils,
|
|
54
|
+
return getDaysInWeekStr(utils, format);
|
|
55
55
|
}
|
|
56
56
|
case 'meridiem':
|
|
57
57
|
{
|
|
@@ -234,17 +234,17 @@ export const changeSectionValueFormat = (utils, valueStr, currentFormat, newForm
|
|
|
234
234
|
}
|
|
235
235
|
return utils.formatByString(utils.parse(valueStr, currentFormat), newFormat);
|
|
236
236
|
};
|
|
237
|
-
const isFourDigitYearFormat = (utils,
|
|
238
|
-
export const doesSectionFormatHaveLeadingZeros = (utils,
|
|
237
|
+
const isFourDigitYearFormat = (utils, format) => utils.formatByString(utils.date(undefined, 'system'), format).length === 4;
|
|
238
|
+
export const doesSectionFormatHaveLeadingZeros = (utils, contentType, sectionType, format) => {
|
|
239
239
|
if (contentType !== 'digit') {
|
|
240
240
|
return false;
|
|
241
241
|
}
|
|
242
|
-
const now = utils.date(undefined,
|
|
242
|
+
const now = utils.date(undefined, 'default');
|
|
243
243
|
switch (sectionType) {
|
|
244
244
|
// We can't use `changeSectionValueFormat`, because `utils.parse('1', 'YYYY')` returns `1971` instead of `1`.
|
|
245
245
|
case 'year':
|
|
246
246
|
{
|
|
247
|
-
if (isFourDigitYearFormat(utils,
|
|
247
|
+
if (isFourDigitYearFormat(utils, format)) {
|
|
248
248
|
const formatted0001 = utils.formatByString(utils.setYear(now, 1), format);
|
|
249
249
|
return formatted0001 === '0001';
|
|
250
250
|
}
|
|
@@ -350,7 +350,7 @@ export const getSectionsBoundaries = (utils, localizedDigits, timezone) => {
|
|
|
350
350
|
format
|
|
351
351
|
}) => ({
|
|
352
352
|
minimum: 0,
|
|
353
|
-
maximum: isFourDigitYearFormat(utils,
|
|
353
|
+
maximum: isFourDigitYearFormat(utils, format) ? 9999 : 99
|
|
354
354
|
}),
|
|
355
355
|
month: () => ({
|
|
356
356
|
minimum: 1,
|
|
@@ -369,7 +369,7 @@ export const getSectionsBoundaries = (utils, localizedDigits, timezone) => {
|
|
|
369
369
|
contentType
|
|
370
370
|
}) => {
|
|
371
371
|
if (contentType === 'digit') {
|
|
372
|
-
const daysInWeek = getDaysInWeekStr(utils,
|
|
372
|
+
const daysInWeek = getDaysInWeekStr(utils, format).map(Number);
|
|
373
373
|
return {
|
|
374
374
|
minimum: Math.min(...daysInWeek),
|
|
375
375
|
maximum: Math.max(...daysInWeek)
|
|
@@ -435,7 +435,7 @@ export const validateSections = (sections, valueType) => {
|
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
437
|
};
|
|
438
|
-
const transferDateSectionValue = (utils,
|
|
438
|
+
const transferDateSectionValue = (utils, section, dateToTransferFrom, dateToTransferTo) => {
|
|
439
439
|
switch (section.type) {
|
|
440
440
|
case 'year':
|
|
441
441
|
{
|
|
@@ -447,7 +447,7 @@ const transferDateSectionValue = (utils, timezone, section, dateToTransferFrom,
|
|
|
447
447
|
}
|
|
448
448
|
case 'weekDay':
|
|
449
449
|
{
|
|
450
|
-
const formattedDaysInWeek = getDaysInWeekStr(utils,
|
|
450
|
+
const formattedDaysInWeek = getDaysInWeekStr(utils, section.format);
|
|
451
451
|
const dayInWeekStrOfActiveDate = utils.formatByString(dateToTransferFrom, section.format);
|
|
452
452
|
const dayInWeekOfActiveDate = formattedDaysInWeek.indexOf(dayInWeekStrOfActiveDate);
|
|
453
453
|
const dayInWeekOfNewSectionValue = formattedDaysInWeek.indexOf(section.value);
|
|
@@ -499,11 +499,11 @@ const reliableSectionModificationOrder = {
|
|
|
499
499
|
meridiem: 8,
|
|
500
500
|
empty: 9
|
|
501
501
|
};
|
|
502
|
-
export const mergeDateIntoReferenceDate = (utils,
|
|
502
|
+
export const mergeDateIntoReferenceDate = (utils, dateToTransferFrom, sections, referenceDate, shouldLimitToEditedSections) =>
|
|
503
503
|
// cloning sections before sort to avoid mutating it
|
|
504
504
|
[...sections].sort((a, b) => reliableSectionModificationOrder[a.type] - reliableSectionModificationOrder[b.type]).reduce((mergedDate, section) => {
|
|
505
505
|
if (!shouldLimitToEditedSections || section.modified) {
|
|
506
|
-
return transferDateSectionValue(utils,
|
|
506
|
+
return transferDateSectionValue(utils, section, dateToTransferFrom, mergedDate);
|
|
507
507
|
}
|
|
508
508
|
return mergedDate;
|
|
509
509
|
}, referenceDate);
|
|
@@ -199,7 +199,7 @@ export const useFieldCharacterEditing = ({
|
|
|
199
199
|
// When editing a letter-format month and the user presses a digit,
|
|
200
200
|
// We can support the numeric editing by using the digit-format month and re-formatting the result.
|
|
201
201
|
if (activeSection.type === 'month') {
|
|
202
|
-
const hasLeadingZerosInFormat = doesSectionFormatHaveLeadingZeros(utils,
|
|
202
|
+
const hasLeadingZerosInFormat = doesSectionFormatHaveLeadingZeros(utils, 'digit', 'month', 'MM');
|
|
203
203
|
const response = getNewSectionValue(queryValue, {
|
|
204
204
|
type: activeSection.type,
|
|
205
205
|
format: 'MM',
|
|
@@ -224,7 +224,7 @@ export const useFieldCharacterEditing = ({
|
|
|
224
224
|
if (isQueryResponseWithoutValue(response)) {
|
|
225
225
|
return response;
|
|
226
226
|
}
|
|
227
|
-
const formattedValue = getDaysInWeekStr(utils,
|
|
227
|
+
const formattedValue = getDaysInWeekStr(utils, activeSection.format)[Number(response.sectionValue) - 1];
|
|
228
228
|
return _extends({}, response, {
|
|
229
229
|
sectionValue: formattedValue
|
|
230
230
|
});
|
|
@@ -48,7 +48,6 @@ export const useFieldState = params => {
|
|
|
48
48
|
const sectionsValueBoundaries = React.useMemo(() => getSectionsBoundaries(utils, localizedDigits, timezone), [utils, localizedDigits, timezone]);
|
|
49
49
|
const getSectionsFromValue = React.useCallback((value, fallbackSections = null) => fieldValueManager.getSectionsFromValue(utils, value, fallbackSections, date => buildSectionsFromFormat({
|
|
50
50
|
utils,
|
|
51
|
-
timezone,
|
|
52
51
|
localeText: translations,
|
|
53
52
|
localizedDigits,
|
|
54
53
|
format,
|
|
@@ -57,7 +56,7 @@ export const useFieldState = params => {
|
|
|
57
56
|
shouldRespectLeadingZeros,
|
|
58
57
|
enableAccessibleFieldDOMStructure,
|
|
59
58
|
isRtl
|
|
60
|
-
})), [fieldValueManager, format, translations, localizedDigits, isRtl, shouldRespectLeadingZeros, utils, formatDensity,
|
|
59
|
+
})), [fieldValueManager, format, translations, localizedDigits, isRtl, shouldRespectLeadingZeros, utils, formatDensity, enableAccessibleFieldDOMStructure]);
|
|
61
60
|
const [state, setState] = React.useState(() => {
|
|
62
61
|
const sections = getSectionsFromValue(valueFromTheOutside);
|
|
63
62
|
validateSections(sections, valueType);
|
|
@@ -154,7 +153,6 @@ export const useFieldState = params => {
|
|
|
154
153
|
}
|
|
155
154
|
const sections = buildSectionsFromFormat({
|
|
156
155
|
utils,
|
|
157
|
-
timezone,
|
|
158
156
|
localeText: translations,
|
|
159
157
|
localizedDigits,
|
|
160
158
|
format,
|
|
@@ -164,7 +162,7 @@ export const useFieldState = params => {
|
|
|
164
162
|
enableAccessibleFieldDOMStructure,
|
|
165
163
|
isRtl
|
|
166
164
|
});
|
|
167
|
-
return mergeDateIntoReferenceDate(utils,
|
|
165
|
+
return mergeDateIntoReferenceDate(utils, date, sections, referenceDate, false);
|
|
168
166
|
};
|
|
169
167
|
const newValue = fieldValueManager.parseValueStr(valueStr, state.referenceValue, parseDateStr);
|
|
170
168
|
const newReferenceValue = fieldValueManager.updateReferenceValue(utils, newValue, state.referenceValue);
|
|
@@ -202,7 +200,7 @@ export const useFieldState = params => {
|
|
|
202
200
|
* This makes sure that we don't lose some information of the initial date (like the time on a date field).
|
|
203
201
|
*/
|
|
204
202
|
if (newActiveDate != null && utils.isValid(newActiveDate)) {
|
|
205
|
-
const mergedDate = mergeDateIntoReferenceDate(utils,
|
|
203
|
+
const mergedDate = mergeDateIntoReferenceDate(utils, newActiveDate, newActiveDateSections, activeDateManager.referenceDate, true);
|
|
206
204
|
values = activeDateManager.getNewValuesFromNewActiveDate(mergedDate);
|
|
207
205
|
shouldPublish = true;
|
|
208
206
|
} else {
|
|
@@ -8,15 +8,16 @@ import useId from '@mui/utils/useId';
|
|
|
8
8
|
import { PickersModalDialog } from "../../components/PickersModalDialog.js";
|
|
9
9
|
import { usePicker } from "../usePicker/index.js";
|
|
10
10
|
import { onSpaceOrEnter } from "../../utils/utils.js";
|
|
11
|
-
import { LocalizationProvider } from "../../../LocalizationProvider/index.js";
|
|
12
11
|
import { PickersLayout } from "../../../PickersLayout/index.js";
|
|
13
|
-
import {
|
|
12
|
+
import { PickersProvider } from "../../components/PickersProvider.js";
|
|
13
|
+
|
|
14
14
|
/**
|
|
15
15
|
* Hook managing all the single-date mobile pickers:
|
|
16
16
|
* - MobileDatePicker
|
|
17
17
|
* - MobileDateTimePicker
|
|
18
18
|
* - MobileTimePicker
|
|
19
19
|
*/
|
|
20
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
21
|
export const useMobilePicker = _ref => {
|
|
21
22
|
let {
|
|
22
23
|
props,
|
|
@@ -49,7 +50,8 @@ export const useMobilePicker = _ref => {
|
|
|
49
50
|
actions,
|
|
50
51
|
layoutProps,
|
|
51
52
|
renderCurrentView,
|
|
52
|
-
fieldProps: pickerFieldProps
|
|
53
|
+
fieldProps: pickerFieldProps,
|
|
54
|
+
contextValue
|
|
53
55
|
} = usePicker(_extends({}, pickerParams, {
|
|
54
56
|
props,
|
|
55
57
|
fieldRef,
|
|
@@ -110,7 +112,8 @@ export const useMobilePicker = _ref => {
|
|
|
110
112
|
}, innerSlotProps?.mobilePaper)
|
|
111
113
|
});
|
|
112
114
|
const handleFieldRef = useForkRef(fieldRef, fieldProps.unstableFieldRef);
|
|
113
|
-
const renderPicker = () => /*#__PURE__*/_jsxs(
|
|
115
|
+
const renderPicker = () => /*#__PURE__*/_jsxs(PickersProvider, {
|
|
116
|
+
contextValue: contextValue,
|
|
114
117
|
localeText: localeText,
|
|
115
118
|
children: [/*#__PURE__*/_jsx(Field, _extends({}, fieldProps, {
|
|
116
119
|
slots: slotsForField,
|
|
@@ -2,6 +2,7 @@ import { warnOnce } from '@mui/x-internals/warning';
|
|
|
2
2
|
import { usePickerValue } from "./usePickerValue.js";
|
|
3
3
|
import { usePickerViews } from "./usePickerViews.js";
|
|
4
4
|
import { usePickerLayoutProps } from "./usePickerLayoutProps.js";
|
|
5
|
+
import { usePickerOwnerState } from "./usePickerOwnerState.js";
|
|
5
6
|
export const usePicker = ({
|
|
6
7
|
props,
|
|
7
8
|
valueManager,
|
|
@@ -39,6 +40,10 @@ export const usePicker = ({
|
|
|
39
40
|
propsFromPickerValue: pickerValueResponse.layoutProps,
|
|
40
41
|
propsFromPickerViews: pickerViewsResponse.layoutProps
|
|
41
42
|
});
|
|
43
|
+
const pickerOwnerState = usePickerOwnerState({
|
|
44
|
+
props,
|
|
45
|
+
pickerValueResponse
|
|
46
|
+
});
|
|
42
47
|
return {
|
|
43
48
|
// Picker value
|
|
44
49
|
open: pickerValueResponse.open,
|
|
@@ -49,6 +54,10 @@ export const usePicker = ({
|
|
|
49
54
|
hasUIView: pickerViewsResponse.hasUIView,
|
|
50
55
|
shouldRestoreFocus: pickerViewsResponse.shouldRestoreFocus,
|
|
51
56
|
// Picker layout
|
|
52
|
-
layoutProps: pickerLayoutResponse.layoutProps
|
|
57
|
+
layoutProps: pickerLayoutResponse.layoutProps,
|
|
58
|
+
// Picker context
|
|
59
|
+
contextValue: pickerValueResponse.contextValue,
|
|
60
|
+
// Picker owner state
|
|
61
|
+
ownerState: pickerOwnerState
|
|
53
62
|
};
|
|
54
63
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UsePickerValueParams, UsePickerValueProps, UsePickerValueBaseProps, UsePickerValueResponse } from './usePickerValue.types';
|
|
2
2
|
import { UsePickerViewsProps, UsePickerViewParams, UsePickerViewsResponse, UsePickerViewsBaseProps } from './usePickerViews';
|
|
3
3
|
import { UsePickerLayoutProps, UsePickerLayoutPropsResponse } from './usePickerLayoutProps';
|
|
4
|
-
import { FieldSection, PickerValidDate } from '../../../models';
|
|
4
|
+
import { FieldSection, PickerOwnerState, PickerValidDate } from '../../../models';
|
|
5
5
|
import { DateOrTimeViewWithMeridiem } from '../../models';
|
|
6
6
|
/**
|
|
7
7
|
* Props common to all picker headless implementations.
|
|
@@ -14,4 +14,5 @@ export interface UsePickerParams<TValue, TDate extends PickerValidDate, TView ex
|
|
|
14
14
|
props: TExternalProps;
|
|
15
15
|
}
|
|
16
16
|
export interface UsePickerResponse<TValue, TView extends DateOrTimeViewWithMeridiem, TSection extends FieldSection, TError> extends Omit<UsePickerValueResponse<TValue, TSection, TError>, 'viewProps' | 'layoutProps'>, Omit<UsePickerViewsResponse<TView>, 'layoutProps'>, UsePickerLayoutPropsResponse<TValue, TView> {
|
|
17
|
+
ownerState: PickerOwnerState<TValue>;
|
|
17
18
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FieldSection, PickerOwnerState } from '../../../models';
|
|
2
|
+
import type { UsePickerProps } from './usePicker.types';
|
|
3
|
+
import { UsePickerValueResponse } from './usePickerValue.types';
|
|
4
|
+
interface UsePickerOwnerStateParameters<TValue> {
|
|
5
|
+
props: UsePickerProps<TValue, any, any, any, any, any>;
|
|
6
|
+
pickerValueResponse: UsePickerValueResponse<TValue, FieldSection, any>;
|
|
7
|
+
}
|
|
8
|
+
export declare function usePickerOwnerState<TValue>(parameters: UsePickerOwnerStateParameters<TValue>): PickerOwnerState<TValue>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export function usePickerOwnerState(parameters) {
|
|
3
|
+
const {
|
|
4
|
+
props,
|
|
5
|
+
pickerValueResponse
|
|
6
|
+
} = parameters;
|
|
7
|
+
return React.useMemo(() => ({
|
|
8
|
+
value: pickerValueResponse.viewProps.value,
|
|
9
|
+
open: pickerValueResponse.open,
|
|
10
|
+
disabled: props.disabled ?? false,
|
|
11
|
+
readOnly: props.readOnly ?? false
|
|
12
|
+
}), [pickerValueResponse.viewProps.value, pickerValueResponse.open, props.disabled, props.readOnly]);
|
|
13
|
+
}
|
|
@@ -5,7 +5,6 @@ import { useOpenState } from "../useOpenState.js";
|
|
|
5
5
|
import { useLocalizationContext, useUtils } from "../useUtils.js";
|
|
6
6
|
import { useValidation } from "../../../validation/index.js";
|
|
7
7
|
import { useValueWithTimezone } from "../useValueWithTimezone.js";
|
|
8
|
-
|
|
9
8
|
/**
|
|
10
9
|
* Decide if the new value should be published
|
|
11
10
|
* The published value will be passed to `onChange` if defined.
|
|
@@ -334,11 +333,17 @@ export const usePickerValue = ({
|
|
|
334
333
|
onSelectShortcut: handleSelectShortcut,
|
|
335
334
|
isValid
|
|
336
335
|
});
|
|
336
|
+
const contextValue = React.useMemo(() => ({
|
|
337
|
+
onOpen: handleOpen,
|
|
338
|
+
onClose: handleClose,
|
|
339
|
+
open: isOpen
|
|
340
|
+
}), [isOpen, handleClose, handleOpen]);
|
|
337
341
|
return {
|
|
338
342
|
open: isOpen,
|
|
339
343
|
fieldProps: fieldResponse,
|
|
340
344
|
viewProps: viewResponse,
|
|
341
345
|
layoutProps: layoutResponse,
|
|
342
|
-
actions
|
|
346
|
+
actions,
|
|
347
|
+
contextValue
|
|
343
348
|
};
|
|
344
349
|
};
|
|
@@ -4,6 +4,7 @@ import { WrapperVariant } from '../../models/common';
|
|
|
4
4
|
import { FieldSection, FieldValueType, TimezoneProps, MuiPickersAdapter, PickersTimezone, PickerChangeHandlerContext, PickerValidDate, OnErrorProps, InferError } from '../../../models';
|
|
5
5
|
import { GetDefaultReferenceDateProps } from '../../utils/getDefaultReferenceDate';
|
|
6
6
|
import { PickerShortcutChangeImportance, PickersShortcutsItemContext } from '../../../PickersShortcuts';
|
|
7
|
+
import { PickersContextValue } from '../../components/PickersProvider';
|
|
7
8
|
export interface PickerValueManager<TValue, TDate extends PickerValidDate, TError> {
|
|
8
9
|
/**
|
|
9
10
|
* Determines if two values are equal.
|
|
@@ -268,4 +269,5 @@ export interface UsePickerValueResponse<TValue, TSection extends FieldSection, T
|
|
|
268
269
|
viewProps: UsePickerValueViewsResponse<TValue>;
|
|
269
270
|
fieldProps: UsePickerValueFieldResponse<TValue, TSection, TError>;
|
|
270
271
|
layoutProps: UsePickerValueLayoutResponse<TValue>;
|
|
272
|
+
contextValue: PickersContextValue;
|
|
271
273
|
}
|
package/internals/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { PickersArrowSwitcher } from './components/PickersArrowSwitcher/PickersArrowSwitcher';
|
|
2
2
|
export type { ExportedPickersArrowSwitcherProps, PickersArrowSwitcherSlots, PickersArrowSwitcherSlotProps, } from './components/PickersArrowSwitcher';
|
|
3
|
+
export { PickersProvider } from './components/PickersProvider';
|
|
3
4
|
export { PickersModalDialog } from './components/PickersModalDialog';
|
|
4
5
|
export type { PickersModalDialogSlots, PickersModalDialogSlotProps, } from './components/PickersModalDialog';
|
|
5
6
|
export { PickersPopper } from './components/PickersPopper';
|
package/internals/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { PickersArrowSwitcher } from "./components/PickersArrowSwitcher/PickersArrowSwitcher.js";
|
|
2
|
+
export { PickersProvider } from "./components/PickersProvider.js";
|
|
2
3
|
export { PickersModalDialog } from "./components/PickersModalDialog.js";
|
|
3
4
|
export { PickersPopper } from "./components/PickersPopper.js";
|
|
4
5
|
export { PickersToolbar } from "./components/PickersToolbar.js";
|
|
@@ -3,4 +3,11 @@ export declare function arrayIncludes<T>(array: T[] | readonly T[], itemOrItems:
|
|
|
3
3
|
export declare const onSpaceOrEnter: (innerFn: (ev: React.MouseEvent<any> | React.KeyboardEvent<any>) => void, externalEvent?: (event: React.KeyboardEvent<any>) => void) => (event: React.KeyboardEvent) => void;
|
|
4
4
|
export declare const executeInTheNextEventLoopTick: (fn: () => void) => void;
|
|
5
5
|
export declare const getActiveElement: (root?: Document | ShadowRoot) => Element | null;
|
|
6
|
+
/**
|
|
7
|
+
* Gets the index of the focused list item in a given ul list element.
|
|
8
|
+
*
|
|
9
|
+
* @param {HTMLUListElement} listElement - The list element to search within.
|
|
10
|
+
* @returns {number} The index of the focused list item, or -1 if none is focused.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getFocusedListItemIndex: (listElement: HTMLUListElement) => number;
|
|
6
13
|
export declare const DEFAULT_DESKTOP_MODE_MEDIA_QUERY = "@media (pointer: fine)";
|
package/internals/utils/utils.js
CHANGED
|
@@ -32,4 +32,15 @@ export const getActiveElement = (root = document) => {
|
|
|
32
32
|
}
|
|
33
33
|
return activeEl;
|
|
34
34
|
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Gets the index of the focused list item in a given ul list element.
|
|
38
|
+
*
|
|
39
|
+
* @param {HTMLUListElement} listElement - The list element to search within.
|
|
40
|
+
* @returns {number} The index of the focused list item, or -1 if none is focused.
|
|
41
|
+
*/
|
|
42
|
+
export const getFocusedListItemIndex = listElement => {
|
|
43
|
+
const children = Array.from(listElement.children);
|
|
44
|
+
return children.indexOf(getActiveElement(document));
|
|
45
|
+
};
|
|
35
46
|
export const DEFAULT_DESKTOP_MODE_MEDIA_QUERY = '@media (pointer: fine)';
|
package/models/pickers.d.ts
CHANGED
|
@@ -9,4 +9,22 @@ export interface PickerChangeHandlerContext<TError> {
|
|
|
9
9
|
}
|
|
10
10
|
export interface PickerValidDateLookup {
|
|
11
11
|
}
|
|
12
|
-
export type PickerValidDate = keyof PickerValidDateLookup extends
|
|
12
|
+
export type PickerValidDate = keyof PickerValidDateLookup extends never ? any : PickerValidDateLookup[keyof PickerValidDateLookup];
|
|
13
|
+
export interface PickerOwnerState<TValue> {
|
|
14
|
+
/**
|
|
15
|
+
* The value currently displayed in the field and in the view.
|
|
16
|
+
*/
|
|
17
|
+
value: TValue;
|
|
18
|
+
/**
|
|
19
|
+
* `true` if the picker is open, `false` otherwise.
|
|
20
|
+
*/
|
|
21
|
+
open: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* `true` if the picker is disabled, `false` otherwise.
|
|
24
|
+
*/
|
|
25
|
+
disabled: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* `true` if the picker is read-only, `false` otherwise.
|
|
28
|
+
*/
|
|
29
|
+
readOnly: boolean;
|
|
30
|
+
}
|
|
@@ -254,6 +254,8 @@ export class AdapterDayjs {
|
|
|
254
254
|
const timezone = this.getTimezone(value);
|
|
255
255
|
if (timezone !== 'UTC') {
|
|
256
256
|
const fixedValue = value.tz(this.cleanTimezone(timezone), true);
|
|
257
|
+
// TODO: Simplify the case when we raise the `dayjs` peer dep to 1.11.12 (https://github.com/iamkun/dayjs/releases/tag/v1.11.12)
|
|
258
|
+
/* istanbul ignore next */
|
|
257
259
|
// @ts-ignore
|
|
258
260
|
if (fixedValue.$offset === (value.$offset ?? 0)) {
|
|
259
261
|
return value;
|
|
@@ -487,7 +487,7 @@ process.env.NODE_ENV !== "production" ? DateCalendar.propTypes = {
|
|
|
487
487
|
/**
|
|
488
488
|
* Component displaying when passed `loading` true.
|
|
489
489
|
* @returns {React.ReactNode} The node to render when loading.
|
|
490
|
-
* @default () => <span
|
|
490
|
+
* @default () => <span>...</span>
|
|
491
491
|
*/
|
|
492
492
|
renderLoading: PropTypes.func,
|
|
493
493
|
/**
|
|
@@ -256,7 +256,7 @@ process.env.NODE_ENV !== "production" ? DatePicker.propTypes = {
|
|
|
256
256
|
/**
|
|
257
257
|
* Component displaying when passed `loading` true.
|
|
258
258
|
* @returns {React.ReactNode} The node to render when loading.
|
|
259
|
-
* @default () => <span
|
|
259
|
+
* @default () => <span>...</span>
|
|
260
260
|
*/
|
|
261
261
|
renderLoading: PropTypes.func,
|
|
262
262
|
/**
|
|
@@ -294,7 +294,7 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
|
|
|
294
294
|
/**
|
|
295
295
|
* Component displaying when passed `loading` true.
|
|
296
296
|
* @returns {React.ReactNode} The node to render when loading.
|
|
297
|
-
* @default () => <span
|
|
297
|
+
* @default () => <span>...</span>
|
|
298
298
|
*/
|
|
299
299
|
renderLoading: PropTypes.func,
|
|
300
300
|
/**
|
|
@@ -87,7 +87,7 @@ const DateTimePickerTabs = function DateTimePickerTabs(inProps) {
|
|
|
87
87
|
variant: "fullWidth",
|
|
88
88
|
value: viewToTab(view),
|
|
89
89
|
onChange: handleChange,
|
|
90
|
-
className: clsx(classes.root
|
|
90
|
+
className: clsx(className, classes.root),
|
|
91
91
|
sx: sx,
|
|
92
92
|
children: [/*#__PURE__*/_jsx(Tab, {
|
|
93
93
|
value: "date",
|
|
@@ -277,7 +277,7 @@ DesktopDatePicker.propTypes = {
|
|
|
277
277
|
/**
|
|
278
278
|
* Component displaying when passed `loading` true.
|
|
279
279
|
* @returns {React.ReactNode} The node to render when loading.
|
|
280
|
-
* @default () => <span
|
|
280
|
+
* @default () => <span>...</span>
|
|
281
281
|
*/
|
|
282
282
|
renderLoading: PropTypes.func,
|
|
283
283
|
/**
|
|
@@ -402,7 +402,7 @@ DesktopDateTimePicker.propTypes = {
|
|
|
402
402
|
/**
|
|
403
403
|
* Component displaying when passed `loading` true.
|
|
404
404
|
* @returns {React.ReactNode} The node to render when loading.
|
|
405
|
-
* @default () => <span
|
|
405
|
+
* @default () => <span>...</span>
|
|
406
406
|
*/
|
|
407
407
|
renderLoading: PropTypes.func,
|
|
408
408
|
/**
|
|
@@ -23,6 +23,7 @@ import { DIGITAL_CLOCK_VIEW_HEIGHT } from "../internals/constants/dimensions.js"
|
|
|
23
23
|
import { useControlledValueWithTimezone } from "../internals/hooks/useValueWithTimezone.js";
|
|
24
24
|
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
25
25
|
import { useClockReferenceDate } from "../internals/hooks/useClockReferenceDate.js";
|
|
26
|
+
import { getFocusedListItemIndex } from "../internals/utils/utils.js";
|
|
26
27
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
27
28
|
const useUtilityClasses = ownerState => {
|
|
28
29
|
const {
|
|
@@ -104,6 +105,7 @@ export const DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(
|
|
|
104
105
|
const utils = useUtils();
|
|
105
106
|
const containerRef = React.useRef(null);
|
|
106
107
|
const handleRef = useForkRef(ref, containerRef);
|
|
108
|
+
const listRef = React.useRef(null);
|
|
107
109
|
const props = useThemeProps({
|
|
108
110
|
props: inProps,
|
|
109
111
|
name: 'MuiDigitalClock'
|
|
@@ -236,15 +238,46 @@ export const DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(
|
|
|
236
238
|
}, (_, index) => utils.addMinutes(startOfDay, timeStep * (index + 1)))];
|
|
237
239
|
}, [valueOrReferenceDate, timeStep, utils]);
|
|
238
240
|
const focusedOptionIndex = timeOptions.findIndex(option => utils.isEqual(option, valueOrReferenceDate));
|
|
241
|
+
const handleKeyDown = event => {
|
|
242
|
+
switch (event.key) {
|
|
243
|
+
case 'PageUp':
|
|
244
|
+
{
|
|
245
|
+
const newIndex = getFocusedListItemIndex(listRef.current) - 5;
|
|
246
|
+
const children = listRef.current.children;
|
|
247
|
+
const newFocusedIndex = Math.max(0, newIndex);
|
|
248
|
+
const childToFocus = children[newFocusedIndex];
|
|
249
|
+
if (childToFocus) {
|
|
250
|
+
childToFocus.focus();
|
|
251
|
+
}
|
|
252
|
+
event.preventDefault();
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case 'PageDown':
|
|
256
|
+
{
|
|
257
|
+
const newIndex = getFocusedListItemIndex(listRef.current) + 5;
|
|
258
|
+
const children = listRef.current.children;
|
|
259
|
+
const newFocusedIndex = Math.min(children.length - 1, newIndex);
|
|
260
|
+
const childToFocus = children[newFocusedIndex];
|
|
261
|
+
if (childToFocus) {
|
|
262
|
+
childToFocus.focus();
|
|
263
|
+
}
|
|
264
|
+
event.preventDefault();
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
default:
|
|
268
|
+
}
|
|
269
|
+
};
|
|
239
270
|
return /*#__PURE__*/_jsx(DigitalClockRoot, _extends({
|
|
240
271
|
ref: handleRef,
|
|
241
272
|
className: clsx(classes.root, className),
|
|
242
273
|
ownerState: ownerState
|
|
243
274
|
}, other, {
|
|
244
275
|
children: /*#__PURE__*/_jsx(DigitalClockList, {
|
|
276
|
+
ref: listRef,
|
|
245
277
|
role: "listbox",
|
|
246
278
|
"aria-label": translations.timePickerToolbarTitle,
|
|
247
279
|
className: classes.list,
|
|
280
|
+
onKeyDown: handleKeyDown,
|
|
248
281
|
children: timeOptions.map((option, index) => {
|
|
249
282
|
if (skipDisabled && isTimeDisabled(option)) {
|
|
250
283
|
return null;
|