Skip to content

Commit f06c8ca

Browse files
Work
1 parent cae8762 commit f06c8ca

File tree

7 files changed

+67
-32
lines changed

7 files changed

+67
-32
lines changed

packages/x-date-pickers/src/DateField/useDateField.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export const useDateField = <
1212
props: TAllProps,
1313
) => {
1414
const valueManager = React.useMemo(
15-
() => getDateValueManager(props.enableAccessibleFieldDOMStructure),
15+
() =>
16+
getDateValueManager({
17+
enableAccessibleFieldDOMStructure: props.enableAccessibleFieldDOMStructure,
18+
}),
1619
[props.enableAccessibleFieldDOMStructure],
1720
);
1821

packages/x-date-pickers/src/DateTimeField/useDateTimeField.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export const useDateTimeField = <
1212
props: TAllProps,
1313
) => {
1414
const valueManager = React.useMemo(
15-
() => getDateTimeValueManager(props.enableAccessibleFieldDOMStructure),
15+
() =>
16+
getDateTimeValueManager({
17+
enableAccessibleFieldDOMStructure: props.enableAccessibleFieldDOMStructure,
18+
}),
1619
[props.enableAccessibleFieldDOMStructure],
1720
);
1821

packages/x-date-pickers/src/TimeField/useTimeField.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export const useTimeField = <
1212
props: TAllProps,
1313
) => {
1414
const valueManager = React.useMemo(
15-
() => getTimeValueManager(props.enableAccessibleFieldDOMStructure),
15+
() =>
16+
getTimeValueManager({
17+
enableAccessibleFieldDOMStructure: props.enableAccessibleFieldDOMStructure,
18+
}),
1619
[props.enableAccessibleFieldDOMStructure],
1720
);
1821

packages/x-date-pickers/src/models/valueManager.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ export interface PickerValueManagerV8<
2222
TError
2323
>,
2424
> {
25-
// The v7 value manager object.
26-
// This will be inlined inside the main `PickerValueManagerV8` object once every object using it is compatible with the new API.
25+
/**
26+
* Object containing basic methods to interact with the value of the picker or field.
27+
* The properties of this object will be inlined inside the main `PickerValueManagerV8` object once every object using it is compatible with the new API.
28+
*/
2729
legacyValueManager: PickerValueManager<TIsRange, TError>;
30+
/**
31+
* Object containing all the necessary methods to interact with the value of the field.
32+
* The properties of this object will be inlined inside the main `PickerValueManagerV8` object once every object using it is compatible with the new API.
33+
*/
2834
fieldValueManager: FieldValueManager<TIsRange>;
2935
/**
3036
* Checks if a value is valid and returns an error code otherwise.
@@ -45,6 +51,10 @@ export interface PickerValueManagerV8<
4551
* The type of the value (e.g. 'date', 'date-time', 'time').
4652
*/
4753
valueType: FieldValueType;
54+
/**
55+
* `true` if the field is using the accessible DOM structure.
56+
* `false` if the field is using the non-accessible legacy DOM structure (which will be deprecated and removed in the future).
57+
*/
4858
enableAccessibleFieldDOMStructure: TEnableAccessibleFieldDOMStructure;
4959
}
5060

@@ -55,10 +65,8 @@ interface ApplyDefaultsToFieldInternalPropsParameters<TFieldInternalProps extend
5565

5666
export type PickerAnyValueManagerV8 = PickerValueManagerV8<any, any, any, any, any>;
5767

58-
export type PickerAnyAccessibleValueManagerV8 = PickerValueManagerV8<any, true, any, any, any>;
59-
6068
/**
61-
* Infer all the usual generic in the picker packages from a `PickerValueManager` interface.
69+
* Infer all the usual generic in the picker packages from a `PickerValueManagerV8` interface.
6270
*/
6371
export type PickerManagerProperties<TManager extends PickerAnyValueManagerV8> =
6472
TManager extends PickerValueManagerV8<

packages/x-date-pickers/src/valueManagers/getDateTimeValueManager.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ export interface DateTimeFieldInternalPropsWithDefaults<
3737
> extends UseFieldInternalProps<false, TEnableAccessibleFieldDOMStructure, DateTimeValidationError>,
3838
ValidateDateTimeProps {}
3939

40+
type DateTimeFieldPropsToDefault =
41+
| 'format'
42+
// minTime and maxTime can still be undefined after applying defaults.
43+
| 'minTime'
44+
| 'maxTime'
45+
| ValidateDateTimePropsToDefault;
46+
4047
export const getDateTimeFieldInternalPropsDefaults = <
4148
TEnableAccessibleFieldDOMStructure extends boolean,
4249
>({
@@ -46,22 +53,18 @@ export const getDateTimeFieldInternalPropsDefaults = <
4653
}: Pick<MuiPickersAdapterContextValue, 'defaultDates' | 'utils'> & {
4754
internalProps: Pick<
4855
DateTimeFieldInternalProps<TEnableAccessibleFieldDOMStructure>,
49-
| 'format'
50-
| 'ampm'
51-
| 'minDateTime'
52-
| 'maxDateTime'
53-
| 'minTime'
54-
| 'maxTime'
55-
| ValidateDateTimePropsToDefault
56+
DateTimeFieldPropsToDefault | 'minDateTime' | 'maxDateTime' | 'ampm'
5657
>;
57-
}) => {
58+
}): Pick<
59+
DateTimeFieldInternalPropsWithDefaults<TEnableAccessibleFieldDOMStructure>,
60+
DateTimeFieldPropsToDefault | 'disableIgnoringDatePartForTimeValidation'
61+
> => {
5862
const ampm = internalProps.ampm ?? utils.is12HourCycleInCurrentLocale();
5963
const defaultFormat = ampm
6064
? utils.formats.keyboardDateTime12h
6165
: utils.formats.keyboardDateTime24h;
6266

6367
return {
64-
ampm,
6568
disablePast: internalProps.disablePast ?? false,
6669
disableFuture: internalProps.disableFuture ?? false,
6770
format: internalProps.format ?? defaultFormat,
@@ -83,9 +86,11 @@ export const getDateTimeFieldInternalPropsDefaults = <
8386
};
8487
};
8588

86-
export const getDateTimeValueManager = <TEnableAccessibleFieldDOMStructure extends boolean = false>(
87-
enableAccessibleFieldDOMStructure: TEnableAccessibleFieldDOMStructure = false as TEnableAccessibleFieldDOMStructure,
88-
): DateTimeValueManager<TEnableAccessibleFieldDOMStructure> => ({
89+
export const getDateTimeValueManager = <TEnableAccessibleFieldDOMStructure extends boolean = true>({
90+
enableAccessibleFieldDOMStructure = true as TEnableAccessibleFieldDOMStructure,
91+
}: {
92+
enableAccessibleFieldDOMStructure: TEnableAccessibleFieldDOMStructure | undefined;
93+
}): DateTimeValueManager<TEnableAccessibleFieldDOMStructure> => ({
8994
legacyValueManager: singleItemValueManager,
9095
fieldValueManager: singleItemFieldValueManager,
9196
validator: validateDateTime,

packages/x-date-pickers/src/valueManagers/getDateValueManager.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export interface DateFieldInternalPropsWithDefaults<
3535
> extends UseFieldInternalProps<false, TEnableAccessibleFieldDOMStructure, DateValidationError>,
3636
ValidateDateProps {}
3737

38+
type DateFieldPropsToDefault = 'format' | ValidateDatePropsToDefault;
39+
3840
export const getDateFieldInternalPropsDefaults = <
3941
TEnableAccessibleFieldDOMStructure extends boolean,
4042
>({
@@ -44,19 +46,24 @@ export const getDateFieldInternalPropsDefaults = <
4446
}: Pick<MuiPickersAdapterContextValue, 'defaultDates' | 'utils'> & {
4547
internalProps: Pick<
4648
DateFieldInternalProps<TEnableAccessibleFieldDOMStructure>,
47-
'format' | ValidateDatePropsToDefault
49+
DateFieldPropsToDefault
4850
>;
49-
}) => ({
51+
}): Pick<
52+
DateFieldInternalPropsWithDefaults<TEnableAccessibleFieldDOMStructure>,
53+
DateFieldPropsToDefault
54+
> => ({
55+
format: internalProps.format ?? utils.formats.keyboardDate,
5056
disablePast: internalProps.disablePast ?? false,
5157
disableFuture: internalProps.disableFuture ?? false,
52-
format: internalProps.format ?? utils.formats.keyboardDate,
5358
minDate: applyDefaultDate(utils, internalProps.minDate, defaultDates.minDate),
5459
maxDate: applyDefaultDate(utils, internalProps.maxDate, defaultDates.maxDate),
5560
});
5661

57-
export const getDateValueManager = <TEnableAccessibleFieldDOMStructure extends boolean = false>(
58-
enableAccessibleFieldDOMStructure: TEnableAccessibleFieldDOMStructure = false as TEnableAccessibleFieldDOMStructure,
59-
): DateValueManager<TEnableAccessibleFieldDOMStructure> => ({
62+
export const getDateValueManager = <TEnableAccessibleFieldDOMStructure extends boolean = true>({
63+
enableAccessibleFieldDOMStructure = true as TEnableAccessibleFieldDOMStructure,
64+
}: {
65+
enableAccessibleFieldDOMStructure: TEnableAccessibleFieldDOMStructure | undefined;
66+
}): DateValueManager<TEnableAccessibleFieldDOMStructure> => ({
6067
legacyValueManager: singleItemValueManager,
6168
fieldValueManager: singleItemFieldValueManager,
6269
validator: validateDate,

packages/x-date-pickers/src/valueManagers/getTimeValueManager.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export interface TimeFieldInternalPropsWithDefaults<
3636
> extends UseFieldInternalProps<false, TEnableAccessibleFieldDOMStructure, TimeValidationError>,
3737
ValidateTimeProps {}
3838

39+
type TimeFieldPropsToDefault = 'format' | ValidateTimePropsToDefault;
40+
3941
export const getTimeFieldInternalPropsDefaults = <
4042
TEnableAccessibleFieldDOMStructure extends boolean,
4143
>({
@@ -44,23 +46,27 @@ export const getTimeFieldInternalPropsDefaults = <
4446
}: Pick<MuiPickersAdapterContextValue, 'utils'> & {
4547
internalProps: Pick<
4648
TimeFieldInternalProps<TEnableAccessibleFieldDOMStructure>,
47-
'format' | 'ampm' | ValidateTimePropsToDefault
49+
TimeFieldPropsToDefault | 'ampm'
4850
>;
49-
}) => {
51+
}): Pick<
52+
TimeFieldInternalPropsWithDefaults<TEnableAccessibleFieldDOMStructure>,
53+
TimeFieldPropsToDefault
54+
> => {
5055
const ampm = internalProps.ampm ?? utils.is12HourCycleInCurrentLocale();
5156
const defaultFormat = ampm ? utils.formats.fullTime12h : utils.formats.fullTime24h;
5257

5358
return {
54-
ampm,
5559
disablePast: internalProps.disablePast ?? false,
5660
disableFuture: internalProps.disableFuture ?? false,
5761
format: internalProps.format ?? defaultFormat,
5862
};
5963
};
6064

61-
export const getTimeValueManager = <TEnableAccessibleFieldDOMStructure extends boolean = false>(
62-
enableAccessibleFieldDOMStructure: TEnableAccessibleFieldDOMStructure = false as TEnableAccessibleFieldDOMStructure,
63-
): TimeValueManager<TEnableAccessibleFieldDOMStructure> => ({
65+
export const getTimeValueManager = <TEnableAccessibleFieldDOMStructure extends boolean = true>({
66+
enableAccessibleFieldDOMStructure = true as TEnableAccessibleFieldDOMStructure,
67+
}: {
68+
enableAccessibleFieldDOMStructure: TEnableAccessibleFieldDOMStructure | undefined;
69+
}): TimeValueManager<TEnableAccessibleFieldDOMStructure> => ({
6470
legacyValueManager: singleItemValueManager,
6571
fieldValueManager: singleItemFieldValueManager,
6672
validator: validateTime,

0 commit comments

Comments
 (0)