@mui/x-date-pickers 8.0.0-alpha.7 → 8.0.0-alpha.8
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/CHANGELOG.md +115 -0
- package/DateField/DateField.js +26 -31
- package/DateField/DateField.types.d.ts +6 -15
- package/DateField/useDateField.d.ts +1 -1
- package/DateField/useDateField.js +2 -1
- package/DateTimeField/DateTimeField.js +26 -31
- package/DateTimeField/DateTimeField.types.d.ts +6 -15
- package/DateTimeField/useDateTimeField.d.ts +1 -1
- package/DateTimeField/useDateTimeField.js +2 -1
- package/DesktopDatePicker/DesktopDatePicker.js +0 -11
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -12
- package/DesktopTimePicker/DesktopTimePicker.js +1 -12
- package/MobileDatePicker/MobileDatePicker.js +0 -9
- package/MobileDateTimePicker/MobileDateTimePicker.js +0 -9
- package/MobileTimePicker/MobileTimePicker.js +0 -9
- package/TimeField/TimeField.js +25 -30
- package/TimeField/TimeField.types.d.ts +6 -15
- package/TimeField/useTimeField.d.ts +1 -1
- package/TimeField/useTimeField.js +2 -1
- package/hooks/useParsedFormat.d.ts +8 -6
- package/hooks/useParsedFormat.js +10 -12
- package/hooks/usePickerActionsContext.d.ts +1 -1
- package/hooks/usePickerContext.d.ts +4 -2
- package/hooks/usePickerContext.js +2 -1
- package/hooks/useSplitFieldProps.d.ts +12 -3
- package/hooks/useSplitFieldProps.js +8 -3
- package/index.js +1 -1
- package/internals/components/PickerFieldUI.d.ts +132 -0
- package/internals/components/PickerFieldUI.js +306 -0
- package/internals/components/PickerProvider.d.ts +25 -4
- package/internals/components/PickerProvider.js +11 -6
- package/internals/hooks/useDesktopPicker/useDesktopPicker.d.ts +1 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +21 -94
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +8 -31
- package/internals/hooks/useField/index.d.ts +3 -1
- package/internals/hooks/useField/index.js +3 -2
- package/internals/hooks/useField/useField.d.ts +1 -10
- package/internals/hooks/useField/useField.js +11 -19
- package/internals/hooks/useField/useField.types.d.ts +11 -4
- package/internals/hooks/useField/useFieldInternalPropsWithDefaults.d.ts +15 -0
- package/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +46 -0
- package/internals/hooks/useField/useFieldV7TextField.js +3 -3
- package/internals/hooks/useFieldOwnerState.d.ts +1 -2
- package/internals/hooks/useMobilePicker/useMobilePicker.d.ts +1 -1
- package/internals/hooks/useMobilePicker/useMobilePicker.js +20 -49
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +6 -14
- package/internals/hooks/useNullablePickerContext.d.ts +5 -0
- package/internals/hooks/useNullablePickerContext.js +10 -0
- package/internals/hooks/usePicker/usePicker.d.ts +1 -2
- package/internals/hooks/usePicker/usePicker.js +0 -3
- package/internals/hooks/usePicker/usePicker.types.d.ts +2 -3
- package/internals/hooks/usePicker/usePickerProvider.d.ts +8 -2
- package/internals/hooks/usePicker/usePickerProvider.js +22 -2
- package/internals/hooks/usePicker/usePickerValue.js +5 -11
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +5 -2
- package/internals/hooks/useUtils.d.ts +4 -3
- package/internals/index.d.ts +6 -3
- package/internals/index.js +1 -1
- package/internals/models/fields.d.ts +3 -16
- package/internals/models/manager.d.ts +3 -0
- package/internals/models/props/basePickerProps.d.ts +0 -12
- package/locales/utils/getPickersLocalization.d.ts +0 -7
- package/locales/utils/getPickersLocalization.js +0 -13
- package/managers/index.d.ts +3 -3
- package/managers/useDateManager.d.ts +1 -1
- package/managers/useDateManager.js +9 -1
- package/managers/useDateTimeManager.d.ts +1 -1
- package/managers/useDateTimeManager.js +9 -1
- package/managers/useTimeManager.d.ts +1 -1
- package/managers/useTimeManager.js +9 -1
- package/models/fields.d.ts +4 -4
- package/models/manager.d.ts +12 -3
- package/modern/DateField/DateField.js +26 -31
- package/modern/DateField/useDateField.js +2 -1
- package/modern/DateTimeField/DateTimeField.js +26 -31
- package/modern/DateTimeField/useDateTimeField.js +2 -1
- package/modern/DesktopDatePicker/DesktopDatePicker.js +0 -11
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -12
- package/modern/DesktopTimePicker/DesktopTimePicker.js +1 -12
- package/modern/MobileDatePicker/MobileDatePicker.js +0 -9
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +0 -9
- package/modern/MobileTimePicker/MobileTimePicker.js +0 -9
- package/modern/TimeField/TimeField.js +25 -30
- package/modern/TimeField/useTimeField.js +2 -1
- package/modern/hooks/useParsedFormat.js +10 -12
- package/modern/hooks/usePickerContext.js +2 -1
- package/modern/hooks/useSplitFieldProps.js +8 -3
- package/modern/index.js +1 -1
- package/modern/internals/components/PickerFieldUI.js +306 -0
- package/modern/internals/components/PickerProvider.js +11 -6
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +21 -94
- package/modern/internals/hooks/useField/index.js +3 -2
- package/modern/internals/hooks/useField/useField.js +11 -19
- package/modern/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +46 -0
- package/modern/internals/hooks/useField/useFieldV7TextField.js +3 -3
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +20 -49
- package/modern/internals/hooks/useNullablePickerContext.js +10 -0
- package/modern/internals/hooks/usePicker/usePicker.js +0 -3
- package/modern/internals/hooks/usePicker/usePickerProvider.js +22 -2
- package/modern/internals/hooks/usePicker/usePickerValue.js +5 -11
- package/modern/internals/index.js +1 -1
- package/modern/locales/utils/getPickersLocalization.js +0 -13
- package/modern/managers/useDateManager.js +9 -1
- package/modern/managers/useDateTimeManager.js +9 -1
- package/modern/managers/useTimeManager.js +9 -1
- package/node/DateField/DateField.js +26 -31
- package/node/DateField/useDateField.js +2 -1
- package/node/DateTimeField/DateTimeField.js +26 -31
- package/node/DateTimeField/useDateTimeField.js +2 -1
- package/node/DesktopDatePicker/DesktopDatePicker.js +0 -11
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -12
- package/node/DesktopTimePicker/DesktopTimePicker.js +1 -12
- package/node/MobileDatePicker/MobileDatePicker.js +0 -9
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +0 -9
- package/node/MobileTimePicker/MobileTimePicker.js +0 -9
- package/node/TimeField/TimeField.js +25 -30
- package/node/TimeField/useTimeField.js +2 -1
- package/node/hooks/useParsedFormat.js +10 -12
- package/node/hooks/usePickerContext.js +4 -3
- package/node/hooks/useSplitFieldProps.js +7 -2
- package/node/index.js +1 -1
- package/node/internals/components/PickerFieldUI.js +318 -0
- package/node/internals/components/PickerProvider.js +13 -8
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +23 -96
- package/node/internals/hooks/useField/index.js +3 -2
- package/node/internals/hooks/useField/useField.js +12 -21
- package/node/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +55 -0
- package/node/internals/hooks/useField/useFieldV7TextField.js +3 -3
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +20 -49
- package/node/internals/hooks/useNullablePickerContext.js +16 -0
- package/node/internals/hooks/usePicker/usePicker.js +0 -3
- package/node/internals/hooks/usePicker/usePickerProvider.js +22 -2
- package/node/internals/hooks/usePicker/usePickerValue.js +5 -11
- package/node/internals/index.js +21 -3
- package/node/locales/utils/getPickersLocalization.js +2 -16
- package/node/managers/useDateManager.js +9 -1
- package/node/managers/useDateTimeManager.js +9 -1
- package/node/managers/useTimeManager.js +9 -1
- package/package.json +2 -2
- package/internals/utils/convertFieldResponseIntoMuiTextFieldProps.d.ts +0 -3
- package/internals/utils/convertFieldResponseIntoMuiTextFieldProps.js +0 -44
- package/modern/internals/utils/convertFieldResponseIntoMuiTextFieldProps.js +0 -44
- package/node/internals/utils/convertFieldResponseIntoMuiTextFieldProps.js +0 -52
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { useField
|
|
1
|
+
export { useField } from './useField';
|
|
2
2
|
export type { FieldValueManager, UseFieldInternalProps, UseFieldParams, UseFieldResponse, FieldChangeHandler, FieldChangeHandlerContext, } from './useField.types';
|
|
3
3
|
export { createDateStrForV7HiddenInputFromSections, createDateStrForV6InputFromSections, } from './useField.utils';
|
|
4
|
+
export { useFieldInternalPropsWithDefaults } from './useFieldInternalPropsWithDefaults';
|
|
5
|
+
export type { PickerFieldPrivateContextValue } from './useFieldInternalPropsWithDefaults';
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { useField
|
|
2
|
-
export { createDateStrForV7HiddenInputFromSections, createDateStrForV6InputFromSections } from "./useField.utils.js";
|
|
1
|
+
export { useField } from "./useField.js";
|
|
2
|
+
export { createDateStrForV7HiddenInputFromSections, createDateStrForV6InputFromSections } from "./useField.utils.js";
|
|
3
|
+
export { useFieldInternalPropsWithDefaults } from "./useFieldInternalPropsWithDefaults.js";
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { UseFieldParams, UseFieldResponse, UseFieldCommonForwardedProps, UseFieldInternalProps, UseFieldForwardedProps } from './useField.types';
|
|
2
|
-
import { PickerValidValue
|
|
3
|
-
/**
|
|
4
|
-
* Applies the default values to the field internal props.
|
|
5
|
-
* This is a temporary hook that will be removed during a follow up when `useField` will receive the internal props without the defaults.
|
|
6
|
-
* It is only here to allow the migration to be done in smaller steps.
|
|
7
|
-
*/
|
|
8
|
-
export declare const useFieldInternalPropsWithDefaults: <TManager extends PickerAnyManager>({ manager, internalProps, }: {
|
|
9
|
-
manager: TManager;
|
|
10
|
-
internalProps: PickerManagerFieldInternalProps<TManager>;
|
|
11
|
-
}) => PickerManagerFieldInternalPropsWithDefaults<TManager>;
|
|
2
|
+
import { PickerValidValue } from '../../models';
|
|
12
3
|
export declare const useField: <TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean, TForwardedProps extends UseFieldCommonForwardedProps & UseFieldForwardedProps<TEnableAccessibleFieldDOMStructure>, TInternalProps extends UseFieldInternalProps<TValue, TEnableAccessibleFieldDOMStructure, any> & {
|
|
13
4
|
minutesStep?: number;
|
|
14
5
|
}>(params: UseFieldParams<TValue, TEnableAccessibleFieldDOMStructure, TForwardedProps, TInternalProps>) => UseFieldResponse<TEnableAccessibleFieldDOMStructure, TForwardedProps>;
|
|
@@ -10,22 +10,6 @@ import { useFieldState } from "./useFieldState.js";
|
|
|
10
10
|
import { useFieldCharacterEditing } from "./useFieldCharacterEditing.js";
|
|
11
11
|
import { useFieldV7TextField } from "./useFieldV7TextField.js";
|
|
12
12
|
import { useFieldV6TextField } from "./useFieldV6TextField.js";
|
|
13
|
-
/**
|
|
14
|
-
* Applies the default values to the field internal props.
|
|
15
|
-
* This is a temporary hook that will be removed during a follow up when `useField` will receive the internal props without the defaults.
|
|
16
|
-
* It is only here to allow the migration to be done in smaller steps.
|
|
17
|
-
*/
|
|
18
|
-
export const useFieldInternalPropsWithDefaults = ({
|
|
19
|
-
manager,
|
|
20
|
-
internalProps
|
|
21
|
-
}) => {
|
|
22
|
-
const localizationContext = useLocalizationContext();
|
|
23
|
-
return React.useMemo(() => {
|
|
24
|
-
return manager.internal_applyDefaultsToFieldInternalProps(_extends({}, localizationContext, {
|
|
25
|
-
internalProps
|
|
26
|
-
}));
|
|
27
|
-
}, [manager, internalProps, localizationContext]);
|
|
28
|
-
};
|
|
29
13
|
export const useField = params => {
|
|
30
14
|
const utils = useUtils();
|
|
31
15
|
const {
|
|
@@ -35,7 +19,8 @@ export const useField = params => {
|
|
|
35
19
|
minutesStep,
|
|
36
20
|
enableAccessibleFieldDOMStructure = true,
|
|
37
21
|
disabled = false,
|
|
38
|
-
readOnly = false
|
|
22
|
+
readOnly = false,
|
|
23
|
+
autoFocus = false
|
|
39
24
|
},
|
|
40
25
|
forwardedProps: {
|
|
41
26
|
onKeyDown,
|
|
@@ -45,7 +30,8 @@ export const useField = params => {
|
|
|
45
30
|
},
|
|
46
31
|
fieldValueManager,
|
|
47
32
|
valueManager,
|
|
48
|
-
validator
|
|
33
|
+
validator,
|
|
34
|
+
getOpenPickerButtonAriaLabel: getOpenDialogAriaText
|
|
49
35
|
} = params;
|
|
50
36
|
const isRtl = useRtl();
|
|
51
37
|
const stateResponse = useFieldState(params);
|
|
@@ -232,9 +218,15 @@ export const useField = params => {
|
|
|
232
218
|
error: inputError,
|
|
233
219
|
clearable: Boolean(clearable && !areAllSectionsEmpty && !readOnly && !disabled)
|
|
234
220
|
};
|
|
221
|
+
const localizationContext = useLocalizationContext();
|
|
222
|
+
const openPickerAriaLabel = React.useMemo(() => getOpenDialogAriaText(_extends({}, localizationContext, {
|
|
223
|
+
value: state.value
|
|
224
|
+
})), [getOpenDialogAriaText, state.value, localizationContext]);
|
|
235
225
|
const commonAdditionalProps = {
|
|
236
226
|
disabled,
|
|
237
|
-
readOnly
|
|
227
|
+
readOnly,
|
|
228
|
+
autoFocus,
|
|
229
|
+
openPickerAriaLabel
|
|
238
230
|
};
|
|
239
231
|
return _extends({}, params.forwardedProps, commonForwardedProps, commonAdditionalProps, returnedValue);
|
|
240
232
|
};
|
|
@@ -5,8 +5,9 @@ import type { Validator } from '../../../validation';
|
|
|
5
5
|
import type { UseFieldStateResponse } from './useFieldState';
|
|
6
6
|
import type { UseFieldCharacterEditingResponse } from './useFieldCharacterEditing';
|
|
7
7
|
import { PickersSectionElement, PickersSectionListRef } from '../../../PickersSectionList';
|
|
8
|
-
import { ExportedUseClearableFieldProps } from '../../../hooks/useClearableField';
|
|
9
8
|
import { FormProps, InferNonNullablePickerValue, PickerValidValue } from '../../models';
|
|
9
|
+
import type { ExportedPickerFieldUIProps } from '../../components/PickerFieldUI';
|
|
10
|
+
import { UseLocalizationContextReturnValue } from '../useUtils';
|
|
10
11
|
export interface UseFieldParams<TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean, TForwardedProps extends UseFieldCommonForwardedProps & UseFieldForwardedProps<TEnableAccessibleFieldDOMStructure>, TInternalProps extends UseFieldInternalProps<TValue, TEnableAccessibleFieldDOMStructure, any>> {
|
|
11
12
|
forwardedProps: TForwardedProps;
|
|
12
13
|
internalProps: TInternalProps;
|
|
@@ -14,6 +15,9 @@ export interface UseFieldParams<TValue extends PickerValidValue, TEnableAccessib
|
|
|
14
15
|
fieldValueManager: FieldValueManager<TValue>;
|
|
15
16
|
validator: Validator<TValue, InferError<TInternalProps>, TInternalProps>;
|
|
16
17
|
valueType: PickerValueType;
|
|
18
|
+
getOpenPickerButtonAriaLabel: (parameters: UseLocalizationContextReturnValue & {
|
|
19
|
+
value: TValue;
|
|
20
|
+
}) => string;
|
|
17
21
|
}
|
|
18
22
|
export interface UseFieldInternalProps<TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean, TError> extends TimezoneProps, FormProps, OnErrorProps<TValue, TError> {
|
|
19
23
|
/**
|
|
@@ -93,9 +97,13 @@ export interface UseFieldInternalProps<TValue extends PickerValidValue, TEnableA
|
|
|
93
97
|
*/
|
|
94
98
|
autoFocus?: boolean;
|
|
95
99
|
}
|
|
96
|
-
export interface UseFieldCommonAdditionalProps extends Required<Pick<UseFieldInternalProps<any, any, any>, 'disabled' | 'readOnly'>> {
|
|
100
|
+
export interface UseFieldCommonAdditionalProps extends Required<Pick<UseFieldInternalProps<any, any, any>, 'disabled' | 'readOnly' | 'autoFocus'>> {
|
|
101
|
+
/**
|
|
102
|
+
* The aria label to set on the button that opens the picker.
|
|
103
|
+
*/
|
|
104
|
+
openPickerAriaLabel: string;
|
|
97
105
|
}
|
|
98
|
-
export interface UseFieldCommonForwardedProps extends
|
|
106
|
+
export interface UseFieldCommonForwardedProps extends Pick<ExportedPickerFieldUIProps, 'clearable' | 'onClear'> {
|
|
99
107
|
onKeyDown?: React.KeyboardEventHandler;
|
|
100
108
|
error?: boolean;
|
|
101
109
|
}
|
|
@@ -113,7 +121,6 @@ interface UseFieldV6AdditionalProps extends Required<Pick<React.InputHTMLAttribu
|
|
|
113
121
|
}
|
|
114
122
|
export interface UseFieldV7ForwardedProps {
|
|
115
123
|
focused?: boolean;
|
|
116
|
-
autoFocus?: boolean;
|
|
117
124
|
sectionListRef?: React.Ref<PickersSectionListRef>;
|
|
118
125
|
onBlur?: () => void;
|
|
119
126
|
onClick?: React.MouseEventHandler;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { UseFieldInternalProps } from './useField.types';
|
|
3
|
+
import { PickerAnyManager, PickerManagerFieldInternalProps, PickerManagerFieldInternalPropsWithDefaults } from '../../models';
|
|
4
|
+
export declare const PickerFieldPrivateContext: React.Context<PickerFieldPrivateContextValue | null>;
|
|
5
|
+
/**
|
|
6
|
+
* Applies the default values to the field internal props.
|
|
7
|
+
* This is a temporary hook that will be removed during a follow up when `useField` will receive the internal props without the defaults.
|
|
8
|
+
* It is only here to allow the migration to be done in smaller steps.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useFieldInternalPropsWithDefaults<TManager extends PickerAnyManager>({ manager, internalProps, }: {
|
|
11
|
+
manager: TManager;
|
|
12
|
+
internalProps: PickerManagerFieldInternalProps<TManager>;
|
|
13
|
+
}): PickerManagerFieldInternalPropsWithDefaults<TManager>;
|
|
14
|
+
export interface PickerFieldPrivateContextValue extends Pick<UseFieldInternalProps<any, any, any>, 'formatDensity' | 'enableAccessibleFieldDOMStructure' | 'selectedSections' | 'onSelectedSectionsChange'> {
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useLocalizationContext } from "../useUtils.js";
|
|
4
|
+
import { useNullablePickerContext } from "../useNullablePickerContext.js";
|
|
5
|
+
export const PickerFieldPrivateContext = /*#__PURE__*/React.createContext(null);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Applies the default values to the field internal props.
|
|
9
|
+
* This is a temporary hook that will be removed during a follow up when `useField` will receive the internal props without the defaults.
|
|
10
|
+
* It is only here to allow the migration to be done in smaller steps.
|
|
11
|
+
*/
|
|
12
|
+
export function useFieldInternalPropsWithDefaults({
|
|
13
|
+
manager,
|
|
14
|
+
internalProps
|
|
15
|
+
}) {
|
|
16
|
+
const localizationContext = useLocalizationContext();
|
|
17
|
+
const pickerContext = useNullablePickerContext();
|
|
18
|
+
const fieldPrivateContext = React.useContext(PickerFieldPrivateContext);
|
|
19
|
+
const setValue = pickerContext?.setValue;
|
|
20
|
+
const handleChangeFromPicker = React.useCallback((newValue, ctx) => {
|
|
21
|
+
return setValue?.(newValue, {
|
|
22
|
+
validationError: ctx.validationError
|
|
23
|
+
});
|
|
24
|
+
}, [setValue]);
|
|
25
|
+
return React.useMemo(() => {
|
|
26
|
+
let internalPropsWithDefaultsFromContext = internalProps;
|
|
27
|
+
// If one of the context is null,
|
|
28
|
+
// Then the field is used as a standalone component and the other context will be null as well.
|
|
29
|
+
if (fieldPrivateContext != null && pickerContext != null) {
|
|
30
|
+
internalPropsWithDefaultsFromContext = _extends({
|
|
31
|
+
value: pickerContext.value,
|
|
32
|
+
onChange: handleChangeFromPicker,
|
|
33
|
+
timezone: pickerContext.timezone,
|
|
34
|
+
disabled: pickerContext.disabled,
|
|
35
|
+
format: pickerContext.fieldFormat,
|
|
36
|
+
formatDensity: fieldPrivateContext.formatDensity,
|
|
37
|
+
enableAccessibleFieldDOMStructure: fieldPrivateContext.enableAccessibleFieldDOMStructure,
|
|
38
|
+
selectedSections: fieldPrivateContext.selectedSections,
|
|
39
|
+
onSelectedSectionsChange: fieldPrivateContext.onSelectedSectionsChange
|
|
40
|
+
}, internalProps);
|
|
41
|
+
}
|
|
42
|
+
return manager.internal_applyDefaultsToFieldInternalProps(_extends({}, localizationContext, {
|
|
43
|
+
internalProps: internalPropsWithDefaultsFromContext
|
|
44
|
+
}));
|
|
45
|
+
}, [manager, localizationContext, pickerContext, fieldPrivateContext, internalProps, handleChangeFromPicker]);
|
|
46
|
+
}
|
|
@@ -11,7 +11,8 @@ export const useFieldV7TextField = params => {
|
|
|
11
11
|
const {
|
|
12
12
|
internalProps: {
|
|
13
13
|
disabled,
|
|
14
|
-
readOnly = false
|
|
14
|
+
readOnly = false,
|
|
15
|
+
autoFocus = false
|
|
15
16
|
},
|
|
16
17
|
forwardedProps: {
|
|
17
18
|
sectionListRef: inSectionListRef,
|
|
@@ -20,8 +21,7 @@ export const useFieldV7TextField = params => {
|
|
|
20
21
|
onFocus,
|
|
21
22
|
onInput,
|
|
22
23
|
onPaste,
|
|
23
|
-
focused: focusedProp
|
|
24
|
-
autoFocus = false
|
|
24
|
+
focused: focusedProp
|
|
25
25
|
},
|
|
26
26
|
fieldValueManager,
|
|
27
27
|
applyCharacterEditing,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FieldOwnerState } from '../../models';
|
|
2
2
|
import { FormProps } from '../models';
|
|
3
3
|
export declare function useFieldOwnerState(parameters: UseFieldOwnerStateParameters): FieldOwnerState;
|
|
4
|
-
interface UseFieldOwnerStateParameters extends FormProps {
|
|
4
|
+
export interface UseFieldOwnerStateParameters extends FormProps {
|
|
5
5
|
required?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export {};
|
|
@@ -7,6 +7,6 @@ import { DateOrTimeViewWithMeridiem } from '../../models';
|
|
|
7
7
|
* - MobileDateTimePicker
|
|
8
8
|
* - MobileTimePicker
|
|
9
9
|
*/
|
|
10
|
-
export declare const useMobilePicker: <TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseMobilePickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>>({ props,
|
|
10
|
+
export declare const useMobilePicker: <TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseMobilePickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>>({ props, ...pickerParams }: UseMobilePickerParams<TView, TEnableAccessibleFieldDOMStructure, TExternalProps>) => {
|
|
11
11
|
renderPicker: () => React.JSX.Element;
|
|
12
12
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["props"
|
|
3
|
+
const _excluded = ["props"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
6
6
|
import useForkRef from '@mui/utils/useForkRef';
|
|
7
7
|
import useId from '@mui/utils/useId';
|
|
8
8
|
import { PickersModalDialog } from "../../components/PickersModalDialog.js";
|
|
9
9
|
import { usePicker } from "../usePicker/index.js";
|
|
10
|
-
import { onSpaceOrEnter } from "../../utils/utils.js";
|
|
11
10
|
import { PickersLayout } from "../../../PickersLayout/index.js";
|
|
12
11
|
import { PickerProvider } from "../../components/PickerProvider.js";
|
|
12
|
+
import { PickerFieldUIContextProvider } from "../../components/PickerFieldUI.js";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Hook managing all the single-date mobile pickers:
|
|
@@ -20,8 +20,7 @@ import { PickerProvider } from "../../components/PickerProvider.js";
|
|
|
20
20
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
21
21
|
export const useMobilePicker = _ref => {
|
|
22
22
|
let {
|
|
23
|
-
props
|
|
24
|
-
getOpenDialogAriaText
|
|
23
|
+
props
|
|
25
24
|
} = _ref,
|
|
26
25
|
pickerParams = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
27
26
|
const {
|
|
@@ -29,17 +28,11 @@ export const useMobilePicker = _ref => {
|
|
|
29
28
|
slotProps: innerSlotProps,
|
|
30
29
|
className,
|
|
31
30
|
sx,
|
|
32
|
-
format,
|
|
33
|
-
formatDensity,
|
|
34
|
-
enableAccessibleFieldDOMStructure,
|
|
35
|
-
selectedSections,
|
|
36
|
-
onSelectedSectionsChange,
|
|
37
|
-
timezone,
|
|
38
31
|
name,
|
|
39
32
|
label,
|
|
40
33
|
inputRef,
|
|
41
34
|
readOnly,
|
|
42
|
-
|
|
35
|
+
autoFocus,
|
|
43
36
|
localeText
|
|
44
37
|
} = props;
|
|
45
38
|
const fieldRef = React.useRef(null);
|
|
@@ -48,7 +41,6 @@ export const useMobilePicker = _ref => {
|
|
|
48
41
|
const {
|
|
49
42
|
providerProps,
|
|
50
43
|
renderCurrentView,
|
|
51
|
-
fieldProps: pickerFieldProps,
|
|
52
44
|
ownerState
|
|
53
45
|
} = usePicker(_extends({}, pickerParams, {
|
|
54
46
|
props,
|
|
@@ -63,44 +55,21 @@ export const useMobilePicker = _ref => {
|
|
|
63
55
|
externalSlotProps: innerSlotProps?.field,
|
|
64
56
|
additionalProps: _extends({
|
|
65
57
|
// Internal props
|
|
66
|
-
readOnly
|
|
67
|
-
|
|
68
|
-
format,
|
|
69
|
-
formatDensity,
|
|
70
|
-
enableAccessibleFieldDOMStructure,
|
|
71
|
-
selectedSections,
|
|
72
|
-
onSelectedSectionsChange,
|
|
73
|
-
timezone
|
|
74
|
-
}, pickerFieldProps, {
|
|
75
|
-
// onChange and value
|
|
76
|
-
|
|
58
|
+
readOnly,
|
|
59
|
+
autoFocus: autoFocus && !props.open,
|
|
77
60
|
// Forwarded props
|
|
78
61
|
className,
|
|
79
62
|
sx,
|
|
80
63
|
label,
|
|
81
|
-
name
|
|
64
|
+
name,
|
|
65
|
+
focused: providerProps.contextValue.open ? true : undefined
|
|
82
66
|
}, isToolbarHidden && {
|
|
83
67
|
id: labelId
|
|
84
|
-
}, !(disabled || readOnly) && {
|
|
85
|
-
// These direct access to `providerProps` will go away in https://github.com/mui/mui-x/pull/15671
|
|
86
|
-
onClick: event => {
|
|
87
|
-
event.preventDefault();
|
|
88
|
-
providerProps.contextValue.setOpen(true);
|
|
89
|
-
},
|
|
90
|
-
onKeyDown: onSpaceOrEnter(() => providerProps.contextValue.setOpen(true))
|
|
91
68
|
}, !!inputRef && {
|
|
92
69
|
inputRef
|
|
93
70
|
}),
|
|
94
71
|
ownerState
|
|
95
72
|
});
|
|
96
|
-
|
|
97
|
-
// TODO: Move to `useSlotProps` when https://github.com/mui/material-ui/pull/35088 will be merged
|
|
98
|
-
fieldProps.inputProps = _extends({}, fieldProps.inputProps, {
|
|
99
|
-
'aria-label': getOpenDialogAriaText(pickerFieldProps.value)
|
|
100
|
-
});
|
|
101
|
-
const slotsForField = _extends({
|
|
102
|
-
textField: slots.textField
|
|
103
|
-
}, fieldProps.slots);
|
|
104
73
|
const Layout = slots.layout ?? PickersLayout;
|
|
105
74
|
let labelledById = labelId;
|
|
106
75
|
if (isToolbarHidden) {
|
|
@@ -119,20 +88,22 @@ export const useMobilePicker = _ref => {
|
|
|
119
88
|
}, innerSlotProps?.mobilePaper)
|
|
120
89
|
});
|
|
121
90
|
const handleFieldRef = useForkRef(fieldRef, fieldProps.unstableFieldRef);
|
|
122
|
-
const renderPicker = () => /*#__PURE__*/
|
|
123
|
-
children:
|
|
124
|
-
slots: slotsForField,
|
|
125
|
-
slotProps: slotProps,
|
|
126
|
-
unstableFieldRef: handleFieldRef
|
|
127
|
-
})), /*#__PURE__*/_jsx(PickersModalDialog, {
|
|
91
|
+
const renderPicker = () => /*#__PURE__*/_jsx(PickerProvider, _extends({}, providerProps, {
|
|
92
|
+
children: /*#__PURE__*/_jsxs(PickerFieldUIContextProvider, {
|
|
128
93
|
slots: slots,
|
|
129
94
|
slotProps: slotProps,
|
|
130
|
-
children: /*#__PURE__*/_jsx(
|
|
95
|
+
children: [/*#__PURE__*/_jsx(Field, _extends({}, fieldProps, {
|
|
96
|
+
unstableFieldRef: handleFieldRef
|
|
97
|
+
})), /*#__PURE__*/_jsx(PickersModalDialog, {
|
|
131
98
|
slots: slots,
|
|
132
99
|
slotProps: slotProps,
|
|
133
|
-
children:
|
|
134
|
-
|
|
135
|
-
|
|
100
|
+
children: /*#__PURE__*/_jsx(Layout, _extends({}, slotProps?.layout, {
|
|
101
|
+
slots: slots,
|
|
102
|
+
slotProps: slotProps,
|
|
103
|
+
children: renderCurrentView()
|
|
104
|
+
}))
|
|
105
|
+
})]
|
|
106
|
+
})
|
|
136
107
|
}));
|
|
137
108
|
return {
|
|
138
109
|
renderPicker
|
|
@@ -1,34 +1,27 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { TextFieldProps } from '@mui/material/TextField';
|
|
3
2
|
import { MakeRequired, SlotComponentPropsFromProps } from '@mui/x-internals/types';
|
|
4
|
-
import {
|
|
3
|
+
import { BasePickerProps, BaseNonRangeNonStaticPickerProps } from '../../models/props/basePickerProps';
|
|
5
4
|
import { PickersModalDialogSlots, PickersModalDialogSlotProps } from '../../components/PickersModalDialog';
|
|
6
5
|
import { UsePickerParams } from '../usePicker';
|
|
7
|
-
import {
|
|
6
|
+
import { PickerFieldSlotProps, PickerOwnerState } from '../../../models';
|
|
8
7
|
import { ExportedPickersLayoutSlots, ExportedPickersLayoutSlotProps, PickersLayoutSlotProps } from '../../../PickersLayout/PickersLayout.types';
|
|
9
8
|
import { UsePickerValueNonStaticProps } from '../usePicker/usePickerValue.types';
|
|
10
9
|
import { UsePickerViewsProps } from '../usePicker/usePickerViews';
|
|
11
10
|
import { DateOrTimeViewWithMeridiem, PickerValue } from '../../models';
|
|
12
|
-
import { PickersTextFieldProps } from '../../../PickersTextField';
|
|
13
11
|
import { UsePickerProviderNonStaticProps } from '../usePicker/usePickerProvider';
|
|
14
|
-
|
|
12
|
+
import { PickerFieldUISlotsFromContext, PickerFieldUISlotPropsFromContext } from '../../components/PickerFieldUI';
|
|
13
|
+
export interface UseMobilePickerSlots extends PickersModalDialogSlots, ExportedPickersLayoutSlots<PickerValue>, PickerFieldUISlotsFromContext {
|
|
15
14
|
/**
|
|
16
15
|
* Component used to enter the date with the keyboard.
|
|
17
16
|
*/
|
|
18
17
|
field: React.ElementType;
|
|
19
|
-
/**
|
|
20
|
-
* Form control with an input to render the value inside the default field.
|
|
21
|
-
* @default TextField from '@mui/material' or PickersTextField if `enableAccessibleFieldDOMStructure` is `true`.
|
|
22
|
-
*/
|
|
23
|
-
textField?: React.ElementType;
|
|
24
18
|
}
|
|
25
|
-
export interface ExportedUseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends PickersModalDialogSlotProps, ExportedPickersLayoutSlotProps<PickerValue
|
|
19
|
+
export interface ExportedUseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends PickersModalDialogSlotProps, ExportedPickersLayoutSlotProps<PickerValue>, PickerFieldUISlotPropsFromContext {
|
|
26
20
|
field?: SlotComponentPropsFromProps<PickerFieldSlotProps<PickerValue, TEnableAccessibleFieldDOMStructure>, {}, PickerOwnerState>;
|
|
27
|
-
textField?: SlotComponentPropsFromProps<PickersTextFieldProps | TextFieldProps, {}, FieldOwnerState>;
|
|
28
21
|
}
|
|
29
22
|
export interface UseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends ExportedUseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure>, Pick<PickersLayoutSlotProps<PickerValue>, 'toolbar'> {
|
|
30
23
|
}
|
|
31
|
-
export interface MobileOnlyPickerProps extends
|
|
24
|
+
export interface MobileOnlyPickerProps extends BaseNonRangeNonStaticPickerProps, UsePickerValueNonStaticProps, UsePickerProviderNonStaticProps {
|
|
32
25
|
}
|
|
33
26
|
export interface UseMobilePickerProps<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError, TExternalProps extends UsePickerViewsProps<any, TView, any>> extends BasePickerProps<PickerValue, TView, TError, TExternalProps>, MakeRequired<MobileOnlyPickerProps, 'format'> {
|
|
34
27
|
/**
|
|
@@ -44,5 +37,4 @@ export interface UseMobilePickerProps<TView extends DateOrTimeViewWithMeridiem,
|
|
|
44
37
|
}
|
|
45
38
|
export interface UseMobilePickerParams<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseMobilePickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>> extends Pick<UsePickerParams<PickerValue, TView, TExternalProps>, 'valueManager' | 'valueType' | 'validator'> {
|
|
46
39
|
props: TExternalProps;
|
|
47
|
-
getOpenDialogAriaText: (date: PickerValidDate | null) => string;
|
|
48
40
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { PickerContext } from "../../hooks/usePickerContext.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns the context passed by the picker that wraps the current component.
|
|
8
|
+
* If the context is not found, returns `null`.
|
|
9
|
+
*/
|
|
10
|
+
export const useNullablePickerContext = () => React.useContext(PickerContext);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { UsePickerParams, UsePickerProps, UsePickerResponse } from './usePicker.types';
|
|
2
|
-
import { InferError } from '../../../models';
|
|
3
2
|
import { DateOrTimeViewWithMeridiem, PickerValidValue } from '../../models';
|
|
4
|
-
export declare const usePicker: <TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerProps<TValue, TView, any, any>>({ props, valueManager, valueType, variant, validator, autoFocusView, rendererInterceptor, fieldRef, localeText, }: UsePickerParams<TValue, TView, TExternalProps>) => UsePickerResponse<TValue, TView
|
|
3
|
+
export declare const usePicker: <TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerProps<TValue, TView, any, any>>({ props, valueManager, valueType, variant, validator, autoFocusView, rendererInterceptor, fieldRef, localeText, }: UsePickerParams<TValue, TView, TExternalProps>) => UsePickerResponse<TValue, TView>;
|
|
@@ -40,11 +40,8 @@ export const usePicker = ({
|
|
|
40
40
|
paramsFromUsePickerViews: pickerViewsResponse.provider
|
|
41
41
|
});
|
|
42
42
|
return {
|
|
43
|
-
// Picker value
|
|
44
|
-
fieldProps: pickerValueResponse.fieldProps,
|
|
45
43
|
// Picker views
|
|
46
44
|
renderCurrentView: pickerViewsResponse.renderCurrentView,
|
|
47
|
-
hasUIView: pickerViewsResponse.provider.hasUIView,
|
|
48
45
|
shouldRestoreFocus: pickerViewsResponse.shouldRestoreFocus,
|
|
49
46
|
// Picker provider
|
|
50
47
|
providerProps,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UsePickerValueParams, UsePickerValueProps, UsePickerValueBaseProps
|
|
1
|
+
import { UsePickerValueParams, UsePickerValueProps, UsePickerValueBaseProps } from './usePickerValue.types';
|
|
2
2
|
import { UsePickerViewsProps, UsePickerViewParams, UsePickerViewsResponse, UsePickerViewsBaseProps } from './usePickerViews';
|
|
3
3
|
import { InferError, PickerOwnerState } from '../../../models';
|
|
4
4
|
import { DateOrTimeViewWithMeridiem, PickerValidValue } from '../../models';
|
|
@@ -13,8 +13,7 @@ export interface UsePickerProps<TValue extends PickerValidValue, TView extends D
|
|
|
13
13
|
export interface UsePickerParams<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerProps<TValue, TView, any, any>> extends Pick<UsePickerValueParams<TValue, TExternalProps>, 'valueManager' | 'valueType' | 'validator'>, Pick<UsePickerViewParams<TValue, TView, TExternalProps>, 'autoFocusView' | 'rendererInterceptor' | 'fieldRef'>, Pick<UsePickerProviderParameters<TValue, TView, InferError<TExternalProps>>, 'localeText' | 'variant'> {
|
|
14
14
|
props: TExternalProps;
|
|
15
15
|
}
|
|
16
|
-
export interface UsePickerResponse<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem
|
|
16
|
+
export interface UsePickerResponse<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem> extends Pick<UsePickerViewsResponse<TView>, 'shouldRestoreFocus' | 'renderCurrentView'> {
|
|
17
17
|
ownerState: PickerOwnerState;
|
|
18
18
|
providerProps: UsePickerProviderReturnValue<TValue>;
|
|
19
|
-
hasUIView: boolean;
|
|
20
19
|
}
|
|
@@ -3,10 +3,11 @@ import { PickerProviderProps } from '../../components/PickerProvider';
|
|
|
3
3
|
import type { UsePickerProps } from './usePicker.types';
|
|
4
4
|
import { DateOrTimeViewWithMeridiem, FormProps, PickerOrientation, PickerValidValue, PickerVariant } from '../../models';
|
|
5
5
|
import { UsePickerViewsProviderParams } from './usePickerViews';
|
|
6
|
+
import { PickerFieldPrivateContextValue } from '../useField/useFieldInternalPropsWithDefaults';
|
|
6
7
|
export declare const usePickerOrientation: (views: readonly DateOrTimeViewWithMeridiem[], customOrientation: PickerOrientation | undefined) => PickerOrientation;
|
|
7
8
|
export declare function usePickerProvider<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError>(parameters: UsePickerProviderParameters<TValue, TView, TError>): UsePickerProviderReturnValue<TValue>;
|
|
8
9
|
export interface UsePickerProviderParameters<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends Pick<PickerProviderProps<TValue>, 'localeText'> {
|
|
9
|
-
props: UsePickerProps<TValue, any, any, any
|
|
10
|
+
props: UsePickerProps<TValue, any, any, any> & UsePickerProviderNonStaticProps;
|
|
10
11
|
valueManager: PickerValueManager<TValue, any>;
|
|
11
12
|
variant: PickerVariant;
|
|
12
13
|
paramsFromUsePickerValue: UsePickerValueProviderParams<TValue, TError>;
|
|
@@ -27,7 +28,12 @@ export interface UsePickerProviderProps extends FormProps {
|
|
|
27
28
|
/**
|
|
28
29
|
* Props used to create the picker's contexts and that are not available on static pickers.
|
|
29
30
|
*/
|
|
30
|
-
export interface UsePickerProviderNonStaticProps {
|
|
31
|
+
export interface UsePickerProviderNonStaticProps extends PickerFieldPrivateContextValue {
|
|
32
|
+
/**
|
|
33
|
+
* Format of the date when rendered in the input(s).
|
|
34
|
+
* Defaults to localized format based on the used `views`.
|
|
35
|
+
*/
|
|
36
|
+
format?: string;
|
|
31
37
|
/**
|
|
32
38
|
* If `true`, the open picker button will not be rendered (renders only the field).
|
|
33
39
|
* @default false
|
|
@@ -45,6 +45,7 @@ export function usePickerProvider(parameters) {
|
|
|
45
45
|
} = parameters;
|
|
46
46
|
const utils = useUtils();
|
|
47
47
|
const orientation = usePickerOrientation(paramsFromUsePickerViews.views, props.orientation);
|
|
48
|
+
const triggerRef = React.useRef(null);
|
|
48
49
|
const ownerState = React.useMemo(() => ({
|
|
49
50
|
isPickerValueEmpty: valueManager.areValuesEqual(utils, paramsFromUsePickerValue.value, valueManager.emptyValue),
|
|
50
51
|
isPickerOpen: paramsFromUsePickerValue.contextValue.open,
|
|
@@ -53,21 +54,40 @@ export function usePickerProvider(parameters) {
|
|
|
53
54
|
pickerOrientation: orientation,
|
|
54
55
|
pickerVariant: variant
|
|
55
56
|
}), [utils, valueManager, paramsFromUsePickerValue.value, paramsFromUsePickerValue.contextValue.open, orientation, variant, props.disabled, props.readOnly]);
|
|
57
|
+
const triggerStatus = React.useMemo(() => {
|
|
58
|
+
if (props.disableOpenPicker || !paramsFromUsePickerViews.hasUIView) {
|
|
59
|
+
return 'hidden';
|
|
60
|
+
}
|
|
61
|
+
if (props.disabled || props.readOnly) {
|
|
62
|
+
return 'disabled';
|
|
63
|
+
}
|
|
64
|
+
return 'enabled';
|
|
65
|
+
}, [props.disableOpenPicker, paramsFromUsePickerViews.hasUIView, props.disabled, props.readOnly]);
|
|
56
66
|
const contextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.contextValue, paramsFromUsePickerViews.contextValue, {
|
|
57
67
|
disabled: props.disabled ?? false,
|
|
58
68
|
readOnly: props.readOnly ?? false,
|
|
59
69
|
variant,
|
|
60
|
-
orientation
|
|
61
|
-
|
|
70
|
+
orientation,
|
|
71
|
+
triggerRef,
|
|
72
|
+
triggerStatus,
|
|
73
|
+
fieldFormat: props.format ?? ''
|
|
74
|
+
}), [paramsFromUsePickerValue.contextValue, paramsFromUsePickerViews.contextValue, variant, orientation, props.disabled, props.readOnly, triggerRef, triggerStatus, props.format]);
|
|
62
75
|
const privateContextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.privateContextValue, {
|
|
63
76
|
ownerState
|
|
64
77
|
}), [paramsFromUsePickerValue, ownerState]);
|
|
65
78
|
const actionsContextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.actionsContextValue, paramsFromUsePickerViews.actionsContextValue), [paramsFromUsePickerValue.actionsContextValue, paramsFromUsePickerViews.actionsContextValue]);
|
|
79
|
+
const fieldPrivateContextValue = React.useMemo(() => ({
|
|
80
|
+
formatDensity: props.formatDensity,
|
|
81
|
+
enableAccessibleFieldDOMStructure: props.enableAccessibleFieldDOMStructure,
|
|
82
|
+
selectedSections: props.selectedSections,
|
|
83
|
+
onSelectedSectionsChange: props.onSelectedSectionsChange
|
|
84
|
+
}), [props.formatDensity, props.enableAccessibleFieldDOMStructure, props.selectedSections, props.onSelectedSectionsChange]);
|
|
66
85
|
return {
|
|
67
86
|
localeText,
|
|
68
87
|
contextValue,
|
|
69
88
|
privateContextValue,
|
|
70
89
|
actionsContextValue,
|
|
90
|
+
fieldPrivateContextValue,
|
|
71
91
|
isValidContextValue: paramsFromUsePickerValue.isValidContextValue
|
|
72
92
|
};
|
|
73
93
|
}
|
|
@@ -176,12 +176,6 @@ export const usePickerValue = ({
|
|
|
176
176
|
skipPublicationIfPristine: true
|
|
177
177
|
});
|
|
178
178
|
});
|
|
179
|
-
const fieldResponse = {
|
|
180
|
-
value: dateState.draft,
|
|
181
|
-
onChange: (newValue, context) => setValue(newValue, {
|
|
182
|
-
validationError: context.validationError
|
|
183
|
-
})
|
|
184
|
-
};
|
|
185
179
|
const setValueFromView = useEventCallback((newValue, selectionState = 'partial') => {
|
|
186
180
|
// TODO: Expose a new method (private?) like `setView` that only updates the draft value.
|
|
187
181
|
if (selectionState === 'shallow') {
|
|
@@ -210,21 +204,21 @@ export const usePickerValue = ({
|
|
|
210
204
|
cancelValueChanges
|
|
211
205
|
}), [setValue, setOpen, clearValue, setValueToToday, acceptValueChanges, cancelValueChanges]);
|
|
212
206
|
const contextValue = React.useMemo(() => _extends({}, actionsContextValue, {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
207
|
+
value: dateState.draft,
|
|
208
|
+
timezone,
|
|
209
|
+
open
|
|
210
|
+
}), [actionsContextValue, timezone, open, dateState.draft]);
|
|
216
211
|
const privateContextValue = React.useMemo(() => ({
|
|
217
212
|
dismissViews
|
|
218
213
|
}), [dismissViews]);
|
|
219
214
|
const providerParams = {
|
|
220
|
-
value:
|
|
215
|
+
value: dateState.draft,
|
|
221
216
|
contextValue,
|
|
222
217
|
actionsContextValue,
|
|
223
218
|
privateContextValue,
|
|
224
219
|
isValidContextValue: isValid
|
|
225
220
|
};
|
|
226
221
|
return {
|
|
227
|
-
fieldProps: fieldResponse,
|
|
228
222
|
viewProps: viewResponse,
|
|
229
223
|
provider: providerParams
|
|
230
224
|
};
|
|
@@ -226,7 +226,6 @@ export interface UsePickerValueProviderParams<TValue extends PickerValidValue, T
|
|
|
226
226
|
}
|
|
227
227
|
export interface UsePickerValueResponse<TValue extends PickerValidValue, TError> {
|
|
228
228
|
viewProps: UsePickerValueViewsResponse<TValue>;
|
|
229
|
-
fieldProps: UsePickerValueFieldResponse<TValue, TError>;
|
|
230
229
|
provider: UsePickerValueProviderParams<TValue, TError>;
|
|
231
230
|
}
|
|
232
231
|
export interface UsePickerValueContextValue<TValue extends PickerValidValue, TError> extends UsePickerValueActionsContextValue<TValue, TError> {
|
|
@@ -234,6 +233,10 @@ export interface UsePickerValueContextValue<TValue extends PickerValidValue, TEr
|
|
|
234
233
|
* The current value of the picker.
|
|
235
234
|
*/
|
|
236
235
|
value: TValue;
|
|
236
|
+
/**
|
|
237
|
+
* The timezone to use when rendering the dates.
|
|
238
|
+
*/
|
|
239
|
+
timezone: PickersTimezone;
|
|
237
240
|
/**
|
|
238
241
|
* `true` if the picker is open, `false` otherwise.
|
|
239
242
|
*/
|
|
@@ -286,7 +289,7 @@ export interface UsePickerValuePrivateContextValue {
|
|
|
286
289
|
*/
|
|
287
290
|
dismissViews: () => void;
|
|
288
291
|
}
|
|
289
|
-
export interface SetValueActionOptions<TError = string> {
|
|
292
|
+
export interface SetValueActionOptions<TError = string | null> {
|
|
290
293
|
/**
|
|
291
294
|
* Importance of the change when picking a value:
|
|
292
295
|
* - "accept": fires `onChange`, fires `onAccept` and closes the picker.
|