@mui/x-date-pickers-pro 8.0.0-alpha.1 → 8.0.0-alpha.3
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 +330 -7
- package/DateRangePicker/DateRangePicker.types.d.ts +2 -2
- package/DateRangePicker/shared.d.ts +3 -2
- package/DateTimeRangePicker/DateTimeRangePicker.types.d.ts +2 -2
- package/DateTimeRangePicker/DateTimeRangePickerTabs.js +8 -7
- package/DateTimeRangePicker/shared.d.ts +4 -3
- package/MultiInputDateRangeField/MultiInputDateRangeField.js +10 -12
- package/MultiInputDateRangeField/MultiInputDateRangeField.types.d.ts +12 -10
- package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +10 -12
- package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.d.ts +11 -9
- package/MultiInputTimeRangeField/MultiInputTimeRangeField.js +10 -12
- package/MultiInputTimeRangeField/MultiInputTimeRangeField.types.d.ts +11 -9
- package/README.md +7 -4
- package/SingleInputDateRangeField/SingleInputDateRangeField.js +5 -5
- package/SingleInputDateRangeField/SingleInputDateRangeField.types.d.ts +11 -10
- package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +5 -5
- package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.types.d.ts +11 -10
- package/SingleInputTimeRangeField/SingleInputTimeRangeField.js +5 -5
- package/SingleInputTimeRangeField/SingleInputTimeRangeField.types.d.ts +10 -9
- package/index.js +1 -1
- package/internals/hooks/models/useRangePicker.d.ts +1 -2
- package/internals/hooks/useDesktopRangePicker/useDesktopRangePicker.js +12 -2
- package/internals/hooks/useEnrichedRangePickerFieldProps.d.ts +13 -12
- package/internals/hooks/useEnrichedRangePickerFieldProps.js +10 -11
- package/internals/hooks/useMobileRangePicker/useMobileRangePicker.js +13 -3
- package/internals/hooks/useMultiInputFieldSelectedSections.d.ts +6 -7
- package/internals/hooks/useRangePosition.d.ts +3 -2
- package/internals/hooks/useStaticRangePicker/useStaticRangePicker.types.d.ts +1 -2
- package/internals/models/dateTimeRange.d.ts +2 -2
- package/internals/models/fields.d.ts +6 -6
- package/internals/models/timeRange.d.ts +2 -2
- package/internals/utils/date-fields-utils.d.ts +6 -6
- package/internals/utils/releaseInfo.js +1 -1
- package/internals/utils/valueManagers.d.ts +4 -3
- package/models/dateRange.d.ts +3 -3
- package/models/fields.d.ts +6 -9
- package/models/index.d.ts +1 -0
- package/models/index.js +2 -1
- package/models/range.d.ts +0 -1
- package/modern/DateTimeRangePicker/DateTimeRangePickerTabs.js +8 -7
- package/modern/MultiInputDateRangeField/MultiInputDateRangeField.js +10 -12
- package/modern/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +10 -12
- package/modern/MultiInputTimeRangeField/MultiInputTimeRangeField.js +10 -12
- package/modern/SingleInputDateRangeField/SingleInputDateRangeField.js +5 -5
- package/modern/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +5 -5
- package/modern/SingleInputTimeRangeField/SingleInputTimeRangeField.js +5 -5
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useDesktopRangePicker/useDesktopRangePicker.js +12 -2
- package/modern/internals/hooks/useEnrichedRangePickerFieldProps.js +10 -11
- package/modern/internals/hooks/useMobileRangePicker/useMobileRangePicker.js +13 -3
- package/modern/internals/utils/releaseInfo.js +1 -1
- package/modern/models/index.js +2 -1
- package/modern/validation/validateDateRange.js +8 -0
- package/modern/validation/validateDateTimeRange.js +4 -0
- package/modern/validation/validateTimeRange.js +8 -0
- package/node/DateTimeRangePicker/DateTimeRangePickerTabs.js +7 -6
- package/node/MultiInputDateRangeField/MultiInputDateRangeField.js +9 -11
- package/node/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +9 -11
- package/node/MultiInputTimeRangeField/MultiInputTimeRangeField.js +9 -11
- package/node/SingleInputDateRangeField/SingleInputDateRangeField.js +4 -4
- package/node/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +4 -4
- package/node/SingleInputTimeRangeField/SingleInputTimeRangeField.js +4 -4
- package/node/index.js +1 -1
- package/node/internals/hooks/useDesktopRangePicker/useDesktopRangePicker.js +12 -2
- package/node/internals/hooks/useEnrichedRangePickerFieldProps.js +10 -11
- package/node/internals/hooks/useMobileRangePicker/useMobileRangePicker.js +13 -3
- package/node/internals/utils/releaseInfo.js +1 -1
- package/node/validation/validateDateRange.js +8 -0
- package/node/validation/validateDateTimeRange.js +4 -0
- package/node/validation/validateTimeRange.js +8 -0
- package/package.json +4 -4
- package/validation/validateDateRange.d.ts +9 -1
- package/validation/validateDateRange.js +8 -0
- package/validation/validateDateTimeRange.d.ts +6 -2
- package/validation/validateDateTimeRange.js +4 -0
- package/validation/validateTimeRange.d.ts +9 -1
- package/validation/validateTimeRange.js +8 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
4
4
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
5
|
-
const _excluded = ["slots", "slotProps", "unstableStartFieldRef", "unstableEndFieldRef", "className"];
|
|
5
|
+
const _excluded = ["slots", "slotProps", "unstableStartFieldRef", "unstableEndFieldRef", "className", "classes"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import clsx from 'clsx';
|
|
@@ -12,17 +12,14 @@ import Typography from '@mui/material/Typography';
|
|
|
12
12
|
import { styled, useThemeProps } from '@mui/material/styles';
|
|
13
13
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
14
14
|
import { unstable_composeClasses as composeClasses, unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses } from '@mui/utils';
|
|
15
|
-
import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals';
|
|
15
|
+
import { convertFieldResponseIntoMuiTextFieldProps, useFieldOwnerState } from '@mui/x-date-pickers/internals';
|
|
16
16
|
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
|
|
17
17
|
import { PickersTextField } from '@mui/x-date-pickers/PickersTextField';
|
|
18
18
|
import { useMultiInputDateTimeRangeField } from "../internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js";
|
|
19
19
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
20
|
export const multiInputDateTimeRangeFieldClasses = generateUtilityClasses('MuiMultiInputDateTimeRangeField', ['root', 'separator']);
|
|
21
21
|
export const getMultiInputDateTimeRangeFieldUtilityClass = slot => generateUtilityClass('MuiMultiInputDateTimeRangeField', slot);
|
|
22
|
-
const useUtilityClasses =
|
|
23
|
-
const {
|
|
24
|
-
classes
|
|
25
|
-
} = ownerState;
|
|
22
|
+
const useUtilityClasses = classes => {
|
|
26
23
|
const slots = {
|
|
27
24
|
root: ['root'],
|
|
28
25
|
separator: ['separator']
|
|
@@ -70,11 +67,12 @@ const MultiInputDateTimeRangeField = /*#__PURE__*/React.forwardRef(function Mult
|
|
|
70
67
|
slotProps,
|
|
71
68
|
unstableStartFieldRef,
|
|
72
69
|
unstableEndFieldRef,
|
|
73
|
-
className
|
|
70
|
+
className,
|
|
71
|
+
classes: classesProp
|
|
74
72
|
} = forwardedProps,
|
|
75
73
|
otherForwardedProps = _objectWithoutPropertiesLoose(forwardedProps, _excluded);
|
|
76
|
-
const ownerState = themeProps;
|
|
77
|
-
const classes = useUtilityClasses(
|
|
74
|
+
const ownerState = useFieldOwnerState(themeProps);
|
|
75
|
+
const classes = useUtilityClasses(classesProp);
|
|
78
76
|
const Root = slots?.root ?? MultiInputDateTimeRangeFieldRoot;
|
|
79
77
|
const rootProps = useSlotProps({
|
|
80
78
|
elementType: Root,
|
|
@@ -298,10 +296,10 @@ process.env.NODE_ENV !== "production" ? MultiInputDateTimeRangeField.propTypes =
|
|
|
298
296
|
*/
|
|
299
297
|
shouldDisableTime: PropTypes.func,
|
|
300
298
|
/**
|
|
301
|
-
* If `true`, the format will respect the leading zeroes (
|
|
302
|
-
* If `false`, the format will always add leading zeroes (
|
|
299
|
+
* If `true`, the format will respect the leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `8/16/2018`)
|
|
300
|
+
* If `false`, the format will always add leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `08/16/2018`)
|
|
303
301
|
*
|
|
304
|
-
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (
|
|
302
|
+
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (for example "DD"), so `shouldRespectLeadingZeros={true}` might lead to inconsistencies when using `AdapterLuxon`.
|
|
305
303
|
*
|
|
306
304
|
* Warning n°2: When `shouldRespectLeadingZeros={true}`, the field will add an invisible character on the sections containing a single digit to make sure `onChange` is fired.
|
|
307
305
|
* If you need to get the clean value from the input, you can remove this character using `input.value.replace(/\u200e/g, '')`.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import type { TypographyProps } from '@mui/material/Typography';
|
|
3
|
+
import type { StackProps } from '@mui/material/Stack';
|
|
4
|
+
import type { TextFieldProps } from '@mui/material/TextField';
|
|
5
|
+
import { FieldOwnerState } from '@mui/x-date-pickers/models';
|
|
6
|
+
import { SlotComponentPropsFromProps } from '@mui/x-internals/types';
|
|
7
|
+
import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField';
|
|
6
8
|
import { UseDateTimeRangeFieldProps } from '../internals/models/dateTimeRange';
|
|
7
9
|
import { UseMultiInputRangeFieldParams } from '../internals/hooks/useMultiInputRangeField/useMultiInputRangeField.types';
|
|
8
10
|
import { MultiInputFieldRefs, MultiInputRangeFieldClasses, RangePosition } from '../models';
|
|
@@ -25,7 +27,7 @@ export interface MultiInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStru
|
|
|
25
27
|
* The props used for each component slot.
|
|
26
28
|
* @default {}
|
|
27
29
|
*/
|
|
28
|
-
slotProps?: MultiInputDateTimeRangeFieldSlotProps
|
|
30
|
+
slotProps?: MultiInputDateTimeRangeFieldSlotProps;
|
|
29
31
|
}
|
|
30
32
|
export interface MultiInputDateTimeRangeFieldSlots {
|
|
31
33
|
/**
|
|
@@ -45,10 +47,10 @@ export interface MultiInputDateTimeRangeFieldSlots {
|
|
|
45
47
|
*/
|
|
46
48
|
separator?: React.ElementType;
|
|
47
49
|
}
|
|
48
|
-
export interface MultiInputDateTimeRangeFieldSlotProps
|
|
49
|
-
root?:
|
|
50
|
-
textField?:
|
|
50
|
+
export interface MultiInputDateTimeRangeFieldSlotProps {
|
|
51
|
+
root?: SlotComponentPropsFromProps<StackProps, {}, FieldOwnerState>;
|
|
52
|
+
textField?: SlotComponentPropsFromProps<PickersTextFieldProps | TextFieldProps, {}, FieldOwnerState & {
|
|
51
53
|
position: RangePosition;
|
|
52
54
|
}>;
|
|
53
|
-
separator?:
|
|
55
|
+
separator?: SlotComponentPropsFromProps<TypographyProps, {}, FieldOwnerState>;
|
|
54
56
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
4
4
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
5
|
-
const _excluded = ["slots", "slotProps", "unstableStartFieldRef", "unstableEndFieldRef", "className"];
|
|
5
|
+
const _excluded = ["slots", "slotProps", "unstableStartFieldRef", "unstableEndFieldRef", "className", "classes"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import { clsx } from 'clsx';
|
|
@@ -12,17 +12,14 @@ import Typography from '@mui/material/Typography';
|
|
|
12
12
|
import { styled, useThemeProps } from '@mui/material/styles';
|
|
13
13
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
14
14
|
import { unstable_composeClasses as composeClasses, unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses } from '@mui/utils';
|
|
15
|
-
import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals';
|
|
15
|
+
import { convertFieldResponseIntoMuiTextFieldProps, useFieldOwnerState } from '@mui/x-date-pickers/internals';
|
|
16
16
|
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
|
|
17
17
|
import { PickersTextField } from '@mui/x-date-pickers/PickersTextField';
|
|
18
18
|
import { useMultiInputTimeRangeField } from "../internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js";
|
|
19
19
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
20
|
export const multiInputTimeRangeFieldClasses = generateUtilityClasses('MuiMultiInputTimeRangeField', ['root', 'separator']);
|
|
21
21
|
export const getMultiInputTimeRangeFieldUtilityClass = slot => generateUtilityClass('MuiMultiInputTimeRangeField', slot);
|
|
22
|
-
const useUtilityClasses =
|
|
23
|
-
const {
|
|
24
|
-
classes
|
|
25
|
-
} = ownerState;
|
|
22
|
+
const useUtilityClasses = classes => {
|
|
26
23
|
const slots = {
|
|
27
24
|
root: ['root'],
|
|
28
25
|
separator: ['separator']
|
|
@@ -70,11 +67,12 @@ const MultiInputTimeRangeField = /*#__PURE__*/React.forwardRef(function MultiInp
|
|
|
70
67
|
slotProps,
|
|
71
68
|
unstableStartFieldRef,
|
|
72
69
|
unstableEndFieldRef,
|
|
73
|
-
className
|
|
70
|
+
className,
|
|
71
|
+
classes: classesProp
|
|
74
72
|
} = forwardedProps,
|
|
75
73
|
otherForwardedProps = _objectWithoutPropertiesLoose(forwardedProps, _excluded);
|
|
76
|
-
const ownerState = themeProps;
|
|
77
|
-
const classes = useUtilityClasses(
|
|
74
|
+
const ownerState = useFieldOwnerState(themeProps);
|
|
75
|
+
const classes = useUtilityClasses(classesProp);
|
|
78
76
|
const Root = slots?.root ?? MultiInputTimeRangeFieldRoot;
|
|
79
77
|
const rootProps = useSlotProps({
|
|
80
78
|
elementType: Root,
|
|
@@ -270,10 +268,10 @@ process.env.NODE_ENV !== "production" ? MultiInputTimeRangeField.propTypes = {
|
|
|
270
268
|
*/
|
|
271
269
|
shouldDisableTime: PropTypes.func,
|
|
272
270
|
/**
|
|
273
|
-
* If `true`, the format will respect the leading zeroes (
|
|
274
|
-
* If `false`, the format will always add leading zeroes (
|
|
271
|
+
* If `true`, the format will respect the leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `8/16/2018`)
|
|
272
|
+
* If `false`, the format will always add leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `08/16/2018`)
|
|
275
273
|
*
|
|
276
|
-
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (
|
|
274
|
+
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (for example "DD"), so `shouldRespectLeadingZeros={true}` might lead to inconsistencies when using `AdapterLuxon`.
|
|
277
275
|
*
|
|
278
276
|
* Warning n°2: When `shouldRespectLeadingZeros={true}`, the field will add an invisible character on the sections containing a single digit to make sure `onChange` is fired.
|
|
279
277
|
* If you need to get the clean value from the input, you can remove this character using `input.value.replace(/\u200e/g, '')`.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import type { TypographyProps } from '@mui/material/Typography';
|
|
3
|
+
import type { StackProps } from '@mui/material/Stack';
|
|
4
|
+
import type { TextFieldProps } from '@mui/material/TextField';
|
|
5
|
+
import { FieldOwnerState } from '@mui/x-date-pickers/models';
|
|
6
|
+
import { SlotComponentPropsFromProps } from '@mui/x-internals/types';
|
|
7
|
+
import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField';
|
|
6
8
|
import { UseTimeRangeFieldProps } from '../internals/models/timeRange';
|
|
7
9
|
import { UseMultiInputRangeFieldParams } from '../internals/hooks/useMultiInputRangeField/useMultiInputRangeField.types';
|
|
8
10
|
import { MultiInputFieldRefs, MultiInputRangeFieldClasses, RangePosition } from '../models';
|
|
@@ -25,7 +27,7 @@ export interface MultiInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructur
|
|
|
25
27
|
* The props used for each component slot.
|
|
26
28
|
* @default {}
|
|
27
29
|
*/
|
|
28
|
-
slotProps?: MultiInputTimeRangeFieldSlotProps
|
|
30
|
+
slotProps?: MultiInputTimeRangeFieldSlotProps;
|
|
29
31
|
}
|
|
30
32
|
export interface MultiInputTimeRangeFieldSlots {
|
|
31
33
|
/**
|
|
@@ -45,10 +47,10 @@ export interface MultiInputTimeRangeFieldSlots {
|
|
|
45
47
|
*/
|
|
46
48
|
separator?: React.ElementType;
|
|
47
49
|
}
|
|
48
|
-
export interface MultiInputTimeRangeFieldSlotProps
|
|
49
|
-
root?:
|
|
50
|
-
textField?:
|
|
50
|
+
export interface MultiInputTimeRangeFieldSlotProps {
|
|
51
|
+
root?: SlotComponentPropsFromProps<StackProps, {}, FieldOwnerState>;
|
|
52
|
+
textField?: SlotComponentPropsFromProps<PickersTextFieldProps | TextFieldProps, {}, FieldOwnerState & {
|
|
51
53
|
position: RangePosition;
|
|
52
54
|
}>;
|
|
53
|
-
separator?:
|
|
55
|
+
separator?: SlotComponentPropsFromProps<TypographyProps, {}, FieldOwnerState>;
|
|
54
56
|
}
|
package/README.md
CHANGED
|
@@ -20,13 +20,16 @@ The pickers currently support the following date libraries:
|
|
|
20
20
|
- [Moment.js](https://momentjs.com/)
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
|
|
23
|
+
# date-fns
|
|
24
24
|
npm install date-fns
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
# or dayjs
|
|
26
27
|
npm install dayjs
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
# or luxon
|
|
28
30
|
npm install luxon
|
|
29
|
-
|
|
31
|
+
|
|
32
|
+
# or moment
|
|
30
33
|
npm install moment
|
|
31
34
|
```
|
|
32
35
|
|
|
@@ -10,7 +10,7 @@ import { useThemeProps } from '@mui/material/styles';
|
|
|
10
10
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
11
11
|
import { refType } from '@mui/utils';
|
|
12
12
|
import { useClearableField } from '@mui/x-date-pickers/hooks';
|
|
13
|
-
import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals';
|
|
13
|
+
import { convertFieldResponseIntoMuiTextFieldProps, useFieldOwnerState } from '@mui/x-date-pickers/internals';
|
|
14
14
|
import { PickersTextField } from '@mui/x-date-pickers/PickersTextField';
|
|
15
15
|
import { useSingleInputDateRangeField } from "./useSingleInputDateRangeField.js";
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -36,7 +36,7 @@ const SingleInputDateRangeField = /*#__PURE__*/React.forwardRef(function SingleI
|
|
|
36
36
|
inputProps
|
|
37
37
|
} = themeProps,
|
|
38
38
|
other = _objectWithoutPropertiesLoose(themeProps, _excluded);
|
|
39
|
-
const ownerState = themeProps;
|
|
39
|
+
const ownerState = useFieldOwnerState(themeProps);
|
|
40
40
|
const TextField = slots?.textField ?? (inProps.enableAccessibleFieldDOMStructure === false ? MuiTextField : PickersTextField);
|
|
41
41
|
const textFieldProps = useSlotProps({
|
|
42
42
|
elementType: TextField,
|
|
@@ -262,10 +262,10 @@ process.env.NODE_ENV !== "production" ? SingleInputDateRangeField.propTypes = {
|
|
|
262
262
|
*/
|
|
263
263
|
shouldDisableDate: PropTypes.func,
|
|
264
264
|
/**
|
|
265
|
-
* If `true`, the format will respect the leading zeroes (
|
|
266
|
-
* If `false`, the format will always add leading zeroes (
|
|
265
|
+
* If `true`, the format will respect the leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `8/16/2018`)
|
|
266
|
+
* If `false`, the format will always add leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `08/16/2018`)
|
|
267
267
|
*
|
|
268
|
-
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (
|
|
268
|
+
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (for example "DD"), so `shouldRespectLeadingZeros={true}` might lead to inconsistencies when using `AdapterLuxon`.
|
|
269
269
|
*
|
|
270
270
|
* Warning n°2: When `shouldRespectLeadingZeros={true}`, the field will add an invisible character on the sections containing a single digit to make sure `onChange` is fired.
|
|
271
271
|
* If you need to get the clean value from the input, you can remove this character using `input.value.replace(/\u200e/g, '')`.
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { BuiltInFieldTextFieldProps } from '@mui/x-date-pickers/models';
|
|
2
|
+
import { TextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
import { SlotComponentPropsFromProps } from '@mui/x-internals/types';
|
|
4
|
+
import { PickerRangeValue, UseFieldInternalProps } from '@mui/x-date-pickers/internals';
|
|
5
|
+
import { BuiltInFieldTextFieldProps, FieldOwnerState } from '@mui/x-date-pickers/models';
|
|
6
6
|
import { ExportedUseClearableFieldProps, UseClearableFieldSlots, UseClearableFieldSlotProps } from '@mui/x-date-pickers/hooks';
|
|
7
|
-
import
|
|
8
|
-
|
|
7
|
+
import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField';
|
|
8
|
+
import type { DateRangeValidationError, UseDateRangeFieldProps } from '../models';
|
|
9
|
+
export interface UseSingleInputDateRangeFieldProps<TEnableAccessibleFieldDOMStructure extends boolean> extends UseDateRangeFieldProps<TEnableAccessibleFieldDOMStructure>, ExportedUseClearableFieldProps, Pick<UseFieldInternalProps<PickerRangeValue, TEnableAccessibleFieldDOMStructure, DateRangeValidationError>, 'unstableFieldRef'> {
|
|
9
10
|
}
|
|
10
11
|
export type SingleInputDateRangeFieldProps<TEnableAccessibleFieldDOMStructure extends boolean = true> = Omit<BuiltInFieldTextFieldProps<TEnableAccessibleFieldDOMStructure>, keyof UseSingleInputDateRangeFieldProps<TEnableAccessibleFieldDOMStructure>> & UseSingleInputDateRangeFieldProps<TEnableAccessibleFieldDOMStructure> & {
|
|
11
12
|
/**
|
|
@@ -17,15 +18,15 @@ export type SingleInputDateRangeFieldProps<TEnableAccessibleFieldDOMStructure ex
|
|
|
17
18
|
* The props used for each component slot.
|
|
18
19
|
* @default {}
|
|
19
20
|
*/
|
|
20
|
-
slotProps?: SingleInputDateRangeFieldSlotProps
|
|
21
|
+
slotProps?: SingleInputDateRangeFieldSlotProps;
|
|
21
22
|
};
|
|
22
23
|
export interface SingleInputDateRangeFieldSlots extends UseClearableFieldSlots {
|
|
23
24
|
/**
|
|
24
25
|
* Form control with an input to render the value.
|
|
25
|
-
* @default TextField from '@mui/material'
|
|
26
|
+
* @default <PickersTextField />, or <TextField /> from '@mui/material' if `enableAccessibleFieldDOMStructure` is `false`.
|
|
26
27
|
*/
|
|
27
28
|
textField?: React.ElementType;
|
|
28
29
|
}
|
|
29
|
-
export interface SingleInputDateRangeFieldSlotProps
|
|
30
|
-
textField?:
|
|
30
|
+
export interface SingleInputDateRangeFieldSlotProps extends UseClearableFieldSlotProps {
|
|
31
|
+
textField?: SlotComponentPropsFromProps<PickersTextFieldProps | TextFieldProps, {}, FieldOwnerState>;
|
|
31
32
|
}
|
|
@@ -6,7 +6,7 @@ const _excluded = ["slots", "slotProps", "InputProps", "inputProps"];
|
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import MuiTextField from '@mui/material/TextField';
|
|
9
|
-
import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals';
|
|
9
|
+
import { convertFieldResponseIntoMuiTextFieldProps, useFieldOwnerState } from '@mui/x-date-pickers/internals';
|
|
10
10
|
import { PickersTextField } from '@mui/x-date-pickers/PickersTextField';
|
|
11
11
|
import { useThemeProps } from '@mui/material/styles';
|
|
12
12
|
import { refType } from '@mui/utils';
|
|
@@ -36,7 +36,7 @@ const SingleInputDateTimeRangeField = /*#__PURE__*/React.forwardRef(function Sin
|
|
|
36
36
|
inputProps
|
|
37
37
|
} = themeProps,
|
|
38
38
|
other = _objectWithoutPropertiesLoose(themeProps, _excluded);
|
|
39
|
-
const ownerState = themeProps;
|
|
39
|
+
const ownerState = useFieldOwnerState(themeProps);
|
|
40
40
|
const TextField = slots?.textField ?? (inProps.enableAccessibleFieldDOMStructure === false ? MuiTextField : PickersTextField);
|
|
41
41
|
const textFieldProps = useSlotProps({
|
|
42
42
|
elementType: TextField,
|
|
@@ -302,10 +302,10 @@ process.env.NODE_ENV !== "production" ? SingleInputDateTimeRangeField.propTypes
|
|
|
302
302
|
*/
|
|
303
303
|
shouldDisableTime: PropTypes.func,
|
|
304
304
|
/**
|
|
305
|
-
* If `true`, the format will respect the leading zeroes (
|
|
306
|
-
* If `false`, the format will always add leading zeroes (
|
|
305
|
+
* If `true`, the format will respect the leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `8/16/2018`)
|
|
306
|
+
* If `false`, the format will always add leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `08/16/2018`)
|
|
307
307
|
*
|
|
308
|
-
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (
|
|
308
|
+
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (for example "DD"), so `shouldRespectLeadingZeros={true}` might lead to inconsistencies when using `AdapterLuxon`.
|
|
309
309
|
*
|
|
310
310
|
* Warning n°2: When `shouldRespectLeadingZeros={true}`, the field will add an invisible character on the sections containing a single digit to make sure `onChange` is fired.
|
|
311
311
|
* If you need to get the clean value from the input, you can remove this character using `input.value.replace(/\u200e/g, '')`.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { TextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
import { SlotComponentPropsFromProps } from '@mui/x-internals/types';
|
|
4
|
+
import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField';
|
|
5
|
+
import { PickerRangeValue, UseFieldInternalProps } from '@mui/x-date-pickers/internals';
|
|
6
|
+
import { BuiltInFieldTextFieldProps, FieldOwnerState } from '@mui/x-date-pickers/models';
|
|
6
7
|
import { ExportedUseClearableFieldProps, UseClearableFieldSlots, UseClearableFieldSlotProps } from '@mui/x-date-pickers/hooks';
|
|
7
8
|
import { UseDateTimeRangeFieldProps } from '../internals/models';
|
|
8
|
-
import {
|
|
9
|
-
export interface UseSingleInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure extends boolean> extends UseDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>, ExportedUseClearableFieldProps, Pick<UseFieldInternalProps<PickerRangeValue,
|
|
9
|
+
import { DateTimeRangeValidationError } from '../models';
|
|
10
|
+
export interface UseSingleInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure extends boolean> extends UseDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>, ExportedUseClearableFieldProps, Pick<UseFieldInternalProps<PickerRangeValue, TEnableAccessibleFieldDOMStructure, DateTimeRangeValidationError>, 'unstableFieldRef'> {
|
|
10
11
|
}
|
|
11
12
|
export type SingleInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure extends boolean = true> = Omit<BuiltInFieldTextFieldProps<TEnableAccessibleFieldDOMStructure>, keyof UseSingleInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>> & UseSingleInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure> & {
|
|
12
13
|
/**
|
|
@@ -18,15 +19,15 @@ export type SingleInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructur
|
|
|
18
19
|
* The props used for each component slot.
|
|
19
20
|
* @default {}
|
|
20
21
|
*/
|
|
21
|
-
slotProps?: SingleInputDateTimeRangeFieldSlotProps
|
|
22
|
+
slotProps?: SingleInputDateTimeRangeFieldSlotProps;
|
|
22
23
|
};
|
|
23
24
|
export interface SingleInputDateTimeRangeFieldSlots extends UseClearableFieldSlots {
|
|
24
25
|
/**
|
|
25
26
|
* Form control with an input to render the value.
|
|
26
|
-
* @default TextField from '@mui/material'
|
|
27
|
+
* @default <PickersTextField />, or <TextField /> from '@mui/material' if `enableAccessibleFieldDOMStructure` is `false`.
|
|
27
28
|
*/
|
|
28
29
|
textField?: React.ElementType;
|
|
29
30
|
}
|
|
30
|
-
export interface SingleInputDateTimeRangeFieldSlotProps
|
|
31
|
-
textField?:
|
|
31
|
+
export interface SingleInputDateTimeRangeFieldSlotProps extends UseClearableFieldSlotProps {
|
|
32
|
+
textField?: SlotComponentPropsFromProps<PickersTextFieldProps | TextFieldProps, {}, FieldOwnerState>;
|
|
32
33
|
}
|
|
@@ -7,7 +7,7 @@ import * as React from 'react';
|
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import MuiTextField from '@mui/material/TextField';
|
|
9
9
|
import { useClearableField } from '@mui/x-date-pickers/hooks';
|
|
10
|
-
import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals';
|
|
10
|
+
import { convertFieldResponseIntoMuiTextFieldProps, useFieldOwnerState } from '@mui/x-date-pickers/internals';
|
|
11
11
|
import { PickersTextField } from '@mui/x-date-pickers/PickersTextField';
|
|
12
12
|
import { useThemeProps } from '@mui/material/styles';
|
|
13
13
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
@@ -36,7 +36,7 @@ const SingleInputTimeRangeField = /*#__PURE__*/React.forwardRef(function SingleI
|
|
|
36
36
|
inputProps
|
|
37
37
|
} = themeProps,
|
|
38
38
|
other = _objectWithoutPropertiesLoose(themeProps, _excluded);
|
|
39
|
-
const ownerState = themeProps;
|
|
39
|
+
const ownerState = useFieldOwnerState(themeProps);
|
|
40
40
|
const TextField = slots?.textField ?? (inProps.enableAccessibleFieldDOMStructure === false ? MuiTextField : PickersTextField);
|
|
41
41
|
const textFieldProps = useSlotProps({
|
|
42
42
|
elementType: TextField,
|
|
@@ -274,10 +274,10 @@ process.env.NODE_ENV !== "production" ? SingleInputTimeRangeField.propTypes = {
|
|
|
274
274
|
*/
|
|
275
275
|
shouldDisableTime: PropTypes.func,
|
|
276
276
|
/**
|
|
277
|
-
* If `true`, the format will respect the leading zeroes (
|
|
278
|
-
* If `false`, the format will always add leading zeroes (
|
|
277
|
+
* If `true`, the format will respect the leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `8/16/2018`)
|
|
278
|
+
* If `false`, the format will always add leading zeroes (for example on dayjs, the format `M/D/YYYY` will render `08/16/2018`)
|
|
279
279
|
*
|
|
280
|
-
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (
|
|
280
|
+
* Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (for example "DD"), so `shouldRespectLeadingZeros={true}` might lead to inconsistencies when using `AdapterLuxon`.
|
|
281
281
|
*
|
|
282
282
|
* Warning n°2: When `shouldRespectLeadingZeros={true}`, the field will add an invisible character on the sections containing a single digit to make sure `onChange` is fired.
|
|
283
283
|
* If you need to get the clean value from the input, you can remove this character using `input.value.replace(/\u200e/g, '')`.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import TextField from '@mui/material/TextField';
|
|
2
|
+
import type { TextFieldProps } from '@mui/material/TextField';
|
|
4
3
|
import { PickerRangeValue, UseFieldInternalProps } from '@mui/x-date-pickers/internals';
|
|
5
|
-
import { BuiltInFieldTextFieldProps } from '@mui/x-date-pickers/models';
|
|
4
|
+
import { BuiltInFieldTextFieldProps, FieldOwnerState } from '@mui/x-date-pickers/models';
|
|
5
|
+
import { SlotComponentPropsFromProps } from '@mui/x-internals/types';
|
|
6
|
+
import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField';
|
|
6
7
|
import { ExportedUseClearableFieldProps, UseClearableFieldSlots, UseClearableFieldSlotProps } from '@mui/x-date-pickers/hooks';
|
|
7
8
|
import { UseTimeRangeFieldProps } from '../internals/models';
|
|
8
|
-
import {
|
|
9
|
-
export interface UseSingleInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure extends boolean> extends UseTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>, ExportedUseClearableFieldProps, Pick<UseFieldInternalProps<PickerRangeValue,
|
|
9
|
+
import { TimeRangeValidationError } from '../models';
|
|
10
|
+
export interface UseSingleInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure extends boolean> extends UseTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>, ExportedUseClearableFieldProps, Pick<UseFieldInternalProps<PickerRangeValue, TEnableAccessibleFieldDOMStructure, TimeRangeValidationError>, 'unstableFieldRef'> {
|
|
10
11
|
}
|
|
11
12
|
export type SingleInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure extends boolean = true> = Omit<BuiltInFieldTextFieldProps<TEnableAccessibleFieldDOMStructure>, keyof UseSingleInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>> & UseSingleInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure> & {
|
|
12
13
|
/**
|
|
@@ -18,15 +19,15 @@ export type SingleInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure ex
|
|
|
18
19
|
* The props used for each component slot.
|
|
19
20
|
* @default {}
|
|
20
21
|
*/
|
|
21
|
-
slotProps?: SingleInputTimeRangeFieldSlotProps
|
|
22
|
+
slotProps?: SingleInputTimeRangeFieldSlotProps;
|
|
22
23
|
};
|
|
23
24
|
export interface SingleInputTimeRangeFieldSlots extends UseClearableFieldSlots {
|
|
24
25
|
/**
|
|
25
26
|
* Form control with an input to render the value.
|
|
26
|
-
* @default TextField from '@mui/material'
|
|
27
|
+
* @default <PickersTextField />, or <TextField /> from '@mui/material' if `enableAccessibleFieldDOMStructure` is `false`.
|
|
27
28
|
*/
|
|
28
29
|
textField?: React.ElementType;
|
|
29
30
|
}
|
|
30
|
-
export interface SingleInputTimeRangeFieldSlotProps
|
|
31
|
-
textField?:
|
|
31
|
+
export interface SingleInputTimeRangeFieldSlotProps extends UseClearableFieldSlotProps {
|
|
32
|
+
textField?: SlotComponentPropsFromProps<PickersTextFieldProps | TextFieldProps, {}, FieldOwnerState>;
|
|
32
33
|
}
|
package/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { ExportedPickersLayoutSlots, ExportedPickersLayoutSlotProps } from '@mui
|
|
|
3
3
|
import { BaseRangeNonStaticPickerProps } from '../../models';
|
|
4
4
|
import { UseRangePositionProps, UseRangePositionResponse } from '../useRangePosition';
|
|
5
5
|
import { RangePickerFieldSlots, RangePickerFieldSlotProps } from '../useEnrichedRangePickerFieldProps';
|
|
6
|
-
import { RangeFieldSection } from '../../../models';
|
|
7
6
|
export interface UseRangePickerSlots<TView extends DateOrTimeViewWithMeridiem> extends ExportedPickersLayoutSlots<PickerRangeValue, TView>, RangePickerFieldSlots {
|
|
8
7
|
}
|
|
9
8
|
export interface UseRangePickerSlotProps<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean> extends ExportedPickersLayoutSlotProps<PickerRangeValue, TView>, RangePickerFieldSlotProps<TEnableAccessibleFieldDOMStructure> {
|
|
@@ -16,6 +15,6 @@ export interface UseRangePickerProps<TView extends DateOrTimeViewWithMeridiem, T
|
|
|
16
15
|
}
|
|
17
16
|
export interface RangePickerAdditionalViewProps extends Pick<UseRangePositionResponse, 'rangePosition' | 'onRangePositionChange'> {
|
|
18
17
|
}
|
|
19
|
-
export interface UseRangePickerParams<TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UseRangePickerProps<TView, any, TExternalProps, TAdditionalViewProps>, TAdditionalViewProps extends {}> extends Pick<UsePickerParams<PickerRangeValue, TView,
|
|
18
|
+
export interface UseRangePickerParams<TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UseRangePickerProps<TView, any, TExternalProps, TAdditionalViewProps>, TAdditionalViewProps extends {}> extends Pick<UsePickerParams<PickerRangeValue, TView, TExternalProps, TAdditionalViewProps>, 'valueManager' | 'valueType' | 'validator' | 'rendererInterceptor'> {
|
|
20
19
|
props: TExternalProps;
|
|
21
20
|
}
|
|
@@ -43,12 +43,21 @@ export const useDesktopRangePicker = _ref => {
|
|
|
43
43
|
const popperRef = React.useRef(null);
|
|
44
44
|
const startFieldRef = React.useRef(null);
|
|
45
45
|
const endFieldRef = React.useRef(null);
|
|
46
|
+
const singleInputFieldRef = React.useRef(null);
|
|
46
47
|
const initialView = React.useRef(props.openTo ?? null);
|
|
47
48
|
const fieldType = slots.field.fieldType ?? 'multi-input';
|
|
48
49
|
const {
|
|
49
50
|
rangePosition,
|
|
50
51
|
onRangePositionChange
|
|
51
|
-
} = useRangePosition(props, fieldType === 'single-input' ?
|
|
52
|
+
} = useRangePosition(props, fieldType === 'single-input' ? singleInputFieldRef : undefined);
|
|
53
|
+
let fieldRef;
|
|
54
|
+
if (fieldType === 'single-input') {
|
|
55
|
+
fieldRef = singleInputFieldRef;
|
|
56
|
+
} else if (rangePosition === 'start') {
|
|
57
|
+
fieldRef = startFieldRef;
|
|
58
|
+
} else {
|
|
59
|
+
fieldRef = endFieldRef;
|
|
60
|
+
}
|
|
52
61
|
const {
|
|
53
62
|
open,
|
|
54
63
|
actions,
|
|
@@ -62,7 +71,7 @@ export const useDesktopRangePicker = _ref => {
|
|
|
62
71
|
props,
|
|
63
72
|
variant: 'desktop',
|
|
64
73
|
autoFocusView: false,
|
|
65
|
-
fieldRef
|
|
74
|
+
fieldRef,
|
|
66
75
|
localeText,
|
|
67
76
|
additionalViewProps: {
|
|
68
77
|
rangePosition,
|
|
@@ -130,6 +139,7 @@ export const useDesktopRangePicker = _ref => {
|
|
|
130
139
|
anchorRef,
|
|
131
140
|
startFieldRef,
|
|
132
141
|
endFieldRef,
|
|
142
|
+
singleInputFieldRef,
|
|
133
143
|
currentView: layoutProps.view !== props.openTo ? layoutProps.view : undefined,
|
|
134
144
|
initialView: initialView.current ?? undefined,
|
|
135
145
|
onViewChange: layoutProps.onViewChange
|
|
@@ -3,12 +3,12 @@ import Stack, { StackProps } from '@mui/material/Stack';
|
|
|
3
3
|
import Typography, { TypographyProps } from '@mui/material/Typography';
|
|
4
4
|
import { SlotComponentProps } from '@mui/utils';
|
|
5
5
|
import { SlotComponentPropsFromProps } from '@mui/x-internals/types';
|
|
6
|
-
import { FieldRef, PickerOwnerState } from '@mui/x-date-pickers/models';
|
|
6
|
+
import { FieldRef, PickerOwnerState, FieldOwnerState } from '@mui/x-date-pickers/models';
|
|
7
7
|
import { UseClearableFieldSlots, UseClearableFieldSlotProps } from '@mui/x-date-pickers/hooks';
|
|
8
8
|
import { PickersInputLocaleText } from '@mui/x-date-pickers/locales';
|
|
9
|
-
import { UsePickerResponse, PickerVariant, DateOrTimeViewWithMeridiem, BaseSingleInputFieldProps, PickerRangeValue } from '@mui/x-date-pickers/internals';
|
|
9
|
+
import { UsePickerResponse, PickerVariant, DateOrTimeViewWithMeridiem, BaseSingleInputFieldProps, PickerRangeValue, PickerValue } from '@mui/x-date-pickers/internals';
|
|
10
10
|
import { PickersTextField } from '@mui/x-date-pickers/PickersTextField';
|
|
11
|
-
import {
|
|
11
|
+
import { RangePosition, FieldType, PickerRangeFieldSlotProps } from '../../models';
|
|
12
12
|
import { UseRangePositionResponse } from './useRangePosition';
|
|
13
13
|
import { BaseMultiInputFieldProps } from '../models/fields';
|
|
14
14
|
export interface RangePickerFieldSlots extends UseClearableFieldSlots {
|
|
@@ -31,15 +31,15 @@ export interface RangePickerFieldSlots extends UseClearableFieldSlots {
|
|
|
31
31
|
textField?: React.ElementType;
|
|
32
32
|
}
|
|
33
33
|
export interface RangePickerFieldSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends UseClearableFieldSlotProps {
|
|
34
|
-
field?: SlotComponentPropsFromProps<PickerRangeFieldSlotProps<
|
|
35
|
-
fieldRoot?: SlotComponentProps<typeof Stack, {},
|
|
36
|
-
fieldSeparator?: SlotComponentProps<typeof Typography, {},
|
|
37
|
-
textField?: SlotComponentProps<typeof PickersTextField, {},
|
|
34
|
+
field?: SlotComponentPropsFromProps<PickerRangeFieldSlotProps<TEnableAccessibleFieldDOMStructure>, {}, PickerOwnerState>;
|
|
35
|
+
fieldRoot?: SlotComponentProps<typeof Stack, {}, FieldOwnerState>;
|
|
36
|
+
fieldSeparator?: SlotComponentProps<typeof Typography, {}, FieldOwnerState>;
|
|
37
|
+
textField?: SlotComponentProps<typeof PickersTextField, {}, FieldOwnerState & {
|
|
38
38
|
position?: RangePosition;
|
|
39
39
|
}>;
|
|
40
40
|
}
|
|
41
|
-
export type RangePickerPropsForFieldSlot<TIsSingleInput extends boolean, TEnableAccessibleFieldDOMStructure extends boolean, TError> = (TIsSingleInput extends true ? BaseSingleInputFieldProps<PickerRangeValue,
|
|
42
|
-
export interface UseEnrichedRangePickerFieldPropsParams<TIsSingleInput extends boolean, TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError> extends Pick<UsePickerResponse<PickerRangeValue, TView,
|
|
41
|
+
export type RangePickerPropsForFieldSlot<TIsSingleInput extends boolean, TEnableAccessibleFieldDOMStructure extends boolean, TError> = (TIsSingleInput extends true ? BaseSingleInputFieldProps<PickerRangeValue, TEnableAccessibleFieldDOMStructure, TError> : never) | (TIsSingleInput extends false ? BaseMultiInputFieldProps<TEnableAccessibleFieldDOMStructure, TError> : never);
|
|
42
|
+
export interface UseEnrichedRangePickerFieldPropsParams<TIsSingleInput extends boolean, TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError> extends Pick<UsePickerResponse<PickerRangeValue, TView, any>, 'open' | 'actions'>, UseRangePositionResponse {
|
|
43
43
|
variant: PickerVariant;
|
|
44
44
|
fieldType: FieldType;
|
|
45
45
|
readOnly?: boolean;
|
|
@@ -55,7 +55,8 @@ export interface UseEnrichedRangePickerFieldPropsParams<TIsSingleInput extends b
|
|
|
55
55
|
currentView?: TView | null;
|
|
56
56
|
initialView?: TView;
|
|
57
57
|
onViewChange?: (view: TView) => void;
|
|
58
|
-
startFieldRef: React.RefObject<FieldRef<
|
|
59
|
-
endFieldRef: React.RefObject<FieldRef<
|
|
58
|
+
startFieldRef: React.RefObject<FieldRef<PickerValue>>;
|
|
59
|
+
endFieldRef: React.RefObject<FieldRef<PickerValue>>;
|
|
60
|
+
singleInputFieldRef: React.RefObject<FieldRef<PickerRangeValue>>;
|
|
60
61
|
}
|
|
61
|
-
export declare const useEnrichedRangePickerFieldProps: <TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError>(params: UseEnrichedRangePickerFieldPropsParams<boolean, TView, TEnableAccessibleFieldDOMStructure, TError>) => BaseMultiInputFieldProps<
|
|
62
|
+
export declare const useEnrichedRangePickerFieldProps: <TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError>(params: UseEnrichedRangePickerFieldPropsParams<boolean, TView, TEnableAccessibleFieldDOMStructure, TError>) => BaseMultiInputFieldProps<TEnableAccessibleFieldDOMStructure, TError> | BaseSingleInputFieldProps<PickerRangeValue, TEnableAccessibleFieldDOMStructure, TError>;
|
|
@@ -156,36 +156,35 @@ const useSingleInputFieldSlotProps = ({
|
|
|
156
156
|
onBlur,
|
|
157
157
|
rangePosition,
|
|
158
158
|
onRangePositionChange,
|
|
159
|
-
|
|
160
|
-
endFieldRef,
|
|
159
|
+
singleInputFieldRef,
|
|
161
160
|
pickerSlots,
|
|
162
161
|
pickerSlotProps,
|
|
163
162
|
fieldProps,
|
|
164
163
|
anchorRef,
|
|
165
164
|
currentView
|
|
166
165
|
}) => {
|
|
167
|
-
const handleFieldRef = useForkRef(fieldProps.unstableFieldRef,
|
|
166
|
+
const handleFieldRef = useForkRef(fieldProps.unstableFieldRef, singleInputFieldRef);
|
|
168
167
|
React.useEffect(() => {
|
|
169
|
-
if (!open || !
|
|
168
|
+
if (!open || !singleInputFieldRef.current || variant === 'mobile') {
|
|
170
169
|
return;
|
|
171
170
|
}
|
|
172
|
-
if (
|
|
171
|
+
if (singleInputFieldRef.current.isFieldFocused()) {
|
|
173
172
|
return;
|
|
174
173
|
}
|
|
175
174
|
|
|
176
175
|
// bring back focus to the field with the current view section selected
|
|
177
176
|
if (currentView) {
|
|
178
|
-
const sections =
|
|
177
|
+
const sections = singleInputFieldRef.current.getSections().map(section => section.type);
|
|
179
178
|
const newSelectedSection = rangePosition === 'start' ? sections.indexOf(currentView) : sections.lastIndexOf(currentView);
|
|
180
|
-
|
|
179
|
+
singleInputFieldRef.current?.focusField(newSelectedSection);
|
|
181
180
|
}
|
|
182
|
-
}, [rangePosition, open, currentView,
|
|
181
|
+
}, [rangePosition, open, currentView, singleInputFieldRef, variant]);
|
|
183
182
|
const updateRangePosition = () => {
|
|
184
|
-
if (!
|
|
183
|
+
if (!singleInputFieldRef.current?.isFieldFocused()) {
|
|
185
184
|
return;
|
|
186
185
|
}
|
|
187
|
-
const sections =
|
|
188
|
-
const activeSectionIndex =
|
|
186
|
+
const sections = singleInputFieldRef.current.getSections();
|
|
187
|
+
const activeSectionIndex = singleInputFieldRef.current?.getActiveSectionIndex();
|
|
189
188
|
const domRangePosition = activeSectionIndex == null || activeSectionIndex < sections.length / 2 ? 'start' : 'end';
|
|
190
189
|
if (domRangePosition != null && domRangePosition !== rangePosition) {
|
|
191
190
|
onRangePositionChange(domRangePosition);
|