@mui/x-date-pickers 8.11.1 → 8.11.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 +181 -0
- package/DateCalendar/DateCalendar.js +1 -0
- package/DateField/DateField.js +6 -3
- package/DateTimeField/DateTimeField.js +6 -3
- package/MonthCalendar/MonthCalendar.js +10 -6
- package/MonthCalendar/MonthCalendar.types.d.ts +1 -0
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +14 -8
- package/TimeField/TimeField.js +6 -3
- package/esm/DateCalendar/DateCalendar.js +1 -0
- package/esm/DateField/DateField.js +7 -4
- package/esm/DateTimeField/DateTimeField.js +7 -4
- package/esm/MonthCalendar/MonthCalendar.js +10 -6
- package/esm/MonthCalendar/MonthCalendar.types.d.ts +1 -0
- package/esm/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +14 -8
- package/esm/TimeField/TimeField.js +7 -4
- package/esm/index.js +1 -1
- package/esm/internals/components/PickerFieldUI.d.ts +0 -10
- package/esm/internals/components/PickerFieldUI.js +56 -21
- package/esm/internals/hooks/useDesktopPicker/useDesktopPicker.js +10 -12
- package/esm/internals/hooks/useField/useFieldSectionContentProps.js +9 -8
- package/esm/internals/hooks/useMobilePicker/useMobilePicker.js +10 -12
- package/index.js +1 -1
- package/internals/components/PickerFieldUI.d.ts +0 -10
- package/internals/components/PickerFieldUI.js +56 -21
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +10 -12
- package/internals/hooks/useField/useFieldSectionContentProps.js +9 -8
- package/internals/hooks/useMobilePicker/useMobilePicker.js +10 -12
- package/package.json +3 -3
|
@@ -17,6 +17,7 @@ import resolveComponentProps from '@mui/utils/resolveComponentProps';
|
|
|
17
17
|
import MuiTextField from '@mui/material/TextField';
|
|
18
18
|
import MuiIconButton from '@mui/material/IconButton';
|
|
19
19
|
import MuiInputAdornment from '@mui/material/InputAdornment';
|
|
20
|
+
import { major as materialMajor } from '@mui/material/version';
|
|
20
21
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
21
22
|
import { useFieldOwnerState } from "../hooks/useFieldOwnerState.js";
|
|
22
23
|
import { usePickerTranslations } from "../../hooks/index.js";
|
|
@@ -24,6 +25,7 @@ import { ClearIcon as MuiClearIcon } from "../../icons/index.js";
|
|
|
24
25
|
import { useNullablePickerContext } from "../hooks/useNullablePickerContext.js";
|
|
25
26
|
import { PickersTextField } from "../../PickersTextField/index.js";
|
|
26
27
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
28
|
+
const noop = () => {};
|
|
27
29
|
export const cleanFieldResponse = _ref => {
|
|
28
30
|
let {
|
|
29
31
|
enableAccessibleFieldDOMStructure
|
|
@@ -40,13 +42,20 @@ export const cleanFieldResponse = _ref => {
|
|
|
40
42
|
openPickerAriaLabel
|
|
41
43
|
} = fieldResponse,
|
|
42
44
|
other = _objectWithoutPropertiesLoose(fieldResponse, _excluded2);
|
|
45
|
+
const mergedInputProps = materialMajor >= 6 && other?.slotProps?.input ? mergeSlotProps(other?.slotProps?.input, InputProps) : noop;
|
|
43
46
|
return {
|
|
44
47
|
clearable,
|
|
45
48
|
onClear,
|
|
46
49
|
clearButtonPosition,
|
|
47
50
|
openPickerButtonPosition,
|
|
48
51
|
openPickerAriaLabel,
|
|
49
|
-
textFieldProps: _extends({}, other, {
|
|
52
|
+
textFieldProps: _extends({}, other, materialMajor >= 6 && other?.slotProps?.input ? {
|
|
53
|
+
slotProps: _extends({}, other?.slotProps, {
|
|
54
|
+
input: ownerState => _extends({}, resolveComponentProps(mergedInputProps, ownerState), {
|
|
55
|
+
readOnly
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
} : {
|
|
50
59
|
InputProps: _extends({}, InputProps ?? {}, {
|
|
51
60
|
readOnly
|
|
52
61
|
})
|
|
@@ -68,13 +77,27 @@ export const cleanFieldResponse = _ref => {
|
|
|
68
77
|
openPickerAriaLabel
|
|
69
78
|
} = fieldResponse,
|
|
70
79
|
other = _objectWithoutPropertiesLoose(fieldResponse, _excluded3);
|
|
80
|
+
const mergedInputProps = materialMajor >= 6 && other?.slotProps?.input ? mergeSlotProps(other?.slotProps?.input, InputProps) : noop;
|
|
81
|
+
const mergedHtmlInputProps = materialMajor >= 6 && other?.slotProps?.htmlInput ? mergeSlotProps(other?.slotProps?.htmlInput, inputProps) : noop;
|
|
71
82
|
return {
|
|
72
83
|
clearable,
|
|
73
84
|
onClear,
|
|
74
85
|
clearButtonPosition,
|
|
75
86
|
openPickerButtonPosition,
|
|
76
87
|
openPickerAriaLabel,
|
|
77
|
-
textFieldProps: _extends({}, other, {
|
|
88
|
+
textFieldProps: _extends({}, other, materialMajor >= 6 && (other?.slotProps?.input || other?.slotProps?.htmlInput) ? {
|
|
89
|
+
slotProps: _extends({}, other?.slotProps, {
|
|
90
|
+
input: ownerState => _extends({}, resolveComponentProps(mergedInputProps, ownerState), {
|
|
91
|
+
readOnly
|
|
92
|
+
}),
|
|
93
|
+
htmlInput: ownerState => _extends({}, resolveComponentProps(mergedHtmlInputProps, ownerState), {
|
|
94
|
+
inputMode,
|
|
95
|
+
onPaste,
|
|
96
|
+
onKeyDown,
|
|
97
|
+
ref: inputRef
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
} : {
|
|
78
101
|
InputProps: _extends({}, InputProps ?? {}, {
|
|
79
102
|
readOnly
|
|
80
103
|
}),
|
|
@@ -100,8 +123,6 @@ export const PickerFieldUIContext = /*#__PURE__*/React.createContext({
|
|
|
100
123
|
if (process.env.NODE_ENV !== "production") PickerFieldUIContext.displayName = "PickerFieldUIContext";
|
|
101
124
|
export function PickerFieldUI(props) {
|
|
102
125
|
const {
|
|
103
|
-
slots,
|
|
104
|
-
slotProps,
|
|
105
126
|
fieldResponse,
|
|
106
127
|
defaultOpenPickerIcon
|
|
107
128
|
} = props;
|
|
@@ -124,11 +145,11 @@ export function PickerFieldUI(props) {
|
|
|
124
145
|
const triggerStatus = pickerContext ? pickerContext.triggerStatus : 'hidden';
|
|
125
146
|
const clearButtonPosition = clearable ? clearButtonPositionProp : null;
|
|
126
147
|
const openPickerButtonPosition = triggerStatus !== 'hidden' ? openPickerButtonPositionProp : null;
|
|
127
|
-
const TextField =
|
|
128
|
-
const InputAdornment =
|
|
148
|
+
const TextField = pickerFieldUIContext.slots.textField ?? (fieldResponse.enableAccessibleFieldDOMStructure === false ? MuiTextField : PickersTextField);
|
|
149
|
+
const InputAdornment = pickerFieldUIContext.slots.inputAdornment ?? MuiInputAdornment;
|
|
129
150
|
const _useSlotProps = useSlotProps({
|
|
130
151
|
elementType: InputAdornment,
|
|
131
|
-
externalSlotProps:
|
|
152
|
+
externalSlotProps: pickerFieldUIContext.slotProps.inputAdornment,
|
|
132
153
|
additionalProps: {
|
|
133
154
|
position: 'start'
|
|
134
155
|
},
|
|
@@ -139,7 +160,7 @@ export function PickerFieldUI(props) {
|
|
|
139
160
|
startInputAdornmentProps = _objectWithoutPropertiesLoose(_useSlotProps, _excluded4);
|
|
140
161
|
const _useSlotProps2 = useSlotProps({
|
|
141
162
|
elementType: InputAdornment,
|
|
142
|
-
externalSlotProps:
|
|
163
|
+
externalSlotProps: pickerFieldUIContext.slotProps.inputAdornment,
|
|
143
164
|
additionalProps: {
|
|
144
165
|
position: 'end'
|
|
145
166
|
},
|
|
@@ -170,11 +191,11 @@ export function PickerFieldUI(props) {
|
|
|
170
191
|
externalSlotProps: pickerFieldUIContext.slotProps.openPickerIcon,
|
|
171
192
|
ownerState
|
|
172
193
|
});
|
|
173
|
-
const ClearButton =
|
|
194
|
+
const ClearButton = pickerFieldUIContext.slots.clearButton ?? MuiIconButton;
|
|
174
195
|
// We don't want to forward the `ownerState` to the `<IconButton />` component, see mui/material-ui#34056
|
|
175
196
|
const _useSlotProps4 = useSlotProps({
|
|
176
197
|
elementType: ClearButton,
|
|
177
|
-
externalSlotProps:
|
|
198
|
+
externalSlotProps: pickerFieldUIContext.slotProps.clearButton,
|
|
178
199
|
className: 'clearButton',
|
|
179
200
|
additionalProps: {
|
|
180
201
|
title: translations.fieldClearLabel,
|
|
@@ -188,24 +209,23 @@ export function PickerFieldUI(props) {
|
|
|
188
209
|
ownerState
|
|
189
210
|
}),
|
|
190
211
|
clearButtonProps = _objectWithoutPropertiesLoose(_useSlotProps4, _excluded7);
|
|
191
|
-
const ClearIcon =
|
|
212
|
+
const ClearIcon = pickerFieldUIContext.slots.clearIcon ?? MuiClearIcon;
|
|
192
213
|
const clearIconProps = useSlotProps({
|
|
193
214
|
elementType: ClearIcon,
|
|
194
|
-
externalSlotProps:
|
|
215
|
+
externalSlotProps: pickerFieldUIContext.slotProps.clearIcon,
|
|
195
216
|
additionalProps: {
|
|
196
217
|
fontSize: 'small'
|
|
197
218
|
},
|
|
198
219
|
ownerState
|
|
199
220
|
});
|
|
200
221
|
textFieldProps.ref = useForkRef(textFieldProps.ref, pickerContext?.rootRef);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
222
|
+
const additionalTextFieldInputProps = {};
|
|
223
|
+
const textFieldInputProps = resolveComponentProps((materialMajor >= 6 && textFieldProps?.slotProps?.input) ?? textFieldProps.InputProps, ownerState);
|
|
204
224
|
if (pickerContext) {
|
|
205
|
-
|
|
225
|
+
additionalTextFieldInputProps.ref = pickerContext.triggerRef;
|
|
206
226
|
}
|
|
207
|
-
if (!
|
|
208
|
-
|
|
227
|
+
if (!textFieldInputProps?.startAdornment && (clearButtonPosition === 'start' || openPickerButtonPosition === 'start')) {
|
|
228
|
+
additionalTextFieldInputProps.startAdornment = /*#__PURE__*/_jsxs(InputAdornment, _extends({}, startInputAdornmentProps, {
|
|
209
229
|
children: [openPickerButtonPosition === 'start' && /*#__PURE__*/_jsx(OpenPickerButton, _extends({}, openPickerButtonProps, {
|
|
210
230
|
children: /*#__PURE__*/_jsx(OpenPickerIcon, _extends({}, openPickerIconProps))
|
|
211
231
|
})), clearButtonPosition === 'start' && /*#__PURE__*/_jsx(ClearButton, _extends({}, clearButtonProps, {
|
|
@@ -213,8 +233,8 @@ export function PickerFieldUI(props) {
|
|
|
213
233
|
}))]
|
|
214
234
|
}));
|
|
215
235
|
}
|
|
216
|
-
if (!
|
|
217
|
-
|
|
236
|
+
if (!textFieldInputProps?.endAdornment && (clearButtonPosition === 'end' || openPickerButtonPosition === 'end')) {
|
|
237
|
+
additionalTextFieldInputProps.endAdornment = /*#__PURE__*/_jsxs(InputAdornment, _extends({}, endInputAdornmentProps, {
|
|
218
238
|
children: [clearButtonPosition === 'end' && /*#__PURE__*/_jsx(ClearButton, _extends({}, clearButtonProps, {
|
|
219
239
|
children: /*#__PURE__*/_jsx(ClearIcon, _extends({}, clearIconProps))
|
|
220
240
|
})), openPickerButtonPosition === 'end' && /*#__PURE__*/_jsx(OpenPickerButton, _extends({}, openPickerButtonProps, {
|
|
@@ -222,6 +242,10 @@ export function PickerFieldUI(props) {
|
|
|
222
242
|
}))]
|
|
223
243
|
}));
|
|
224
244
|
}
|
|
245
|
+
// handle the case of showing custom `inputAdornment` for Field components
|
|
246
|
+
if (!additionalTextFieldInputProps?.endAdornment && !additionalTextFieldInputProps?.startAdornment && pickerFieldUIContext.slots.inputAdornment) {
|
|
247
|
+
additionalTextFieldInputProps.endAdornment = /*#__PURE__*/_jsx(InputAdornment, _extends({}, endInputAdornmentProps));
|
|
248
|
+
}
|
|
225
249
|
if (clearButtonPosition != null) {
|
|
226
250
|
textFieldProps.sx = [{
|
|
227
251
|
'& .clearButton': {
|
|
@@ -239,7 +263,18 @@ export function PickerFieldUI(props) {
|
|
|
239
263
|
}
|
|
240
264
|
}, ...(Array.isArray(textFieldProps.sx) ? textFieldProps.sx : [textFieldProps.sx])];
|
|
241
265
|
}
|
|
242
|
-
|
|
266
|
+
const resolvedTextFieldInputProps = materialMajor >= 6 && textFieldProps?.slotProps?.input ? resolveComponentProps(mergeSlotProps(textFieldInputProps, additionalTextFieldInputProps), ownerState) : _extends({}, textFieldInputProps, additionalTextFieldInputProps);
|
|
267
|
+
|
|
268
|
+
// Remove the `input` slotProps to avoid them overriding the manually resolved `InputProps`.
|
|
269
|
+
// Relevant on `materialMajor >= 6` since `slotProps` would take precedence.
|
|
270
|
+
delete textFieldProps?.slotProps?.input;
|
|
271
|
+
if (fieldResponse.enableAccessibleFieldDOMStructure) {
|
|
272
|
+
// Remove the `slotProps` on `PickersTextField` as they are not supported.
|
|
273
|
+
delete textFieldProps?.slotProps;
|
|
274
|
+
}
|
|
275
|
+
return /*#__PURE__*/_jsx(TextField, _extends({}, textFieldProps, {
|
|
276
|
+
InputProps: resolvedTextFieldInputProps
|
|
277
|
+
}));
|
|
243
278
|
}
|
|
244
279
|
export function mergeSlotProps(slotPropsA, slotPropsB) {
|
|
245
280
|
if (!slotPropsA) {
|
|
@@ -8,7 +8,6 @@ import { PickerPopper } from "../../components/PickerPopper/PickerPopper.js";
|
|
|
8
8
|
import { usePicker } from "../usePicker/index.js";
|
|
9
9
|
import { PickersLayout } from "../../../PickersLayout/index.js";
|
|
10
10
|
import { PickerProvider } from "../../components/PickerProvider.js";
|
|
11
|
-
import { PickerFieldUIContextProvider } from "../../components/PickerFieldUI.js";
|
|
12
11
|
import { createNonRangePickerStepNavigation } from "../../utils/createNonRangePickerStepNavigation.js";
|
|
13
12
|
|
|
14
13
|
/**
|
|
@@ -75,21 +74,20 @@ export const useDesktopPicker = _ref => {
|
|
|
75
74
|
'aria-labelledby': labelledById
|
|
76
75
|
}, innerSlotProps?.popper)
|
|
77
76
|
});
|
|
78
|
-
const renderPicker = () => /*#__PURE__*/
|
|
79
|
-
children: /*#__PURE__*/
|
|
77
|
+
const renderPicker = () => /*#__PURE__*/_jsxs(PickerProvider, _extends({}, providerProps, {
|
|
78
|
+
children: [/*#__PURE__*/_jsx(Field, _extends({}, fieldProps, {
|
|
80
79
|
slots: slots,
|
|
81
80
|
slotProps: slotProps,
|
|
82
|
-
inputRef: inputRef
|
|
83
|
-
|
|
81
|
+
inputRef: inputRef
|
|
82
|
+
})), /*#__PURE__*/_jsx(PickerPopper, {
|
|
83
|
+
slots: slots,
|
|
84
|
+
slotProps: slotProps,
|
|
85
|
+
children: /*#__PURE__*/_jsx(Layout, _extends({}, slotProps?.layout, {
|
|
84
86
|
slots: slots,
|
|
85
87
|
slotProps: slotProps,
|
|
86
|
-
children:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
children: renderCurrentView()
|
|
90
|
-
}))
|
|
91
|
-
})]
|
|
92
|
-
})
|
|
88
|
+
children: renderCurrentView()
|
|
89
|
+
}))
|
|
90
|
+
})]
|
|
93
91
|
}));
|
|
94
92
|
if (process.env.NODE_ENV !== "production") renderPicker.displayName = "renderPicker";
|
|
95
93
|
return {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
3
|
-
import useId from '@mui/utils/useId';
|
|
4
3
|
import { usePickerAdapter, usePickerTranslations } from "../../../hooks/index.js";
|
|
5
4
|
import { syncSelectionToDOM } from "./syncSelectionToDOM.js";
|
|
6
5
|
/**
|
|
@@ -13,7 +12,6 @@ import { syncSelectionToDOM } from "./syncSelectionToDOM.js";
|
|
|
13
12
|
export function useFieldSectionContentProps(parameters) {
|
|
14
13
|
const adapter = usePickerAdapter();
|
|
15
14
|
const translations = usePickerTranslations();
|
|
16
|
-
const id = useId();
|
|
17
15
|
const {
|
|
18
16
|
focused,
|
|
19
17
|
domGetters,
|
|
@@ -147,7 +145,6 @@ export function useFieldSectionContentProps(parameters) {
|
|
|
147
145
|
onDragOver: handleDragOver,
|
|
148
146
|
onFocus: createFocusHandler(sectionIndex),
|
|
149
147
|
// Aria attributes
|
|
150
|
-
'aria-labelledby': `${id}-${section.type}`,
|
|
151
148
|
'aria-readonly': readOnly,
|
|
152
149
|
'aria-valuenow': getSectionValueNow(section, adapter),
|
|
153
150
|
'aria-valuemin': sectionBoundaries.minimum,
|
|
@@ -159,7 +156,6 @@ export function useFieldSectionContentProps(parameters) {
|
|
|
159
156
|
tabIndex: isContainerEditable || sectionIndex > 0 ? -1 : 0,
|
|
160
157
|
contentEditable: !isContainerEditable && !disabled && !readOnly,
|
|
161
158
|
role: 'spinbutton',
|
|
162
|
-
id: `${id}-${section.type}`,
|
|
163
159
|
'data-range-position': section.dateName || undefined,
|
|
164
160
|
spellCheck: isEditable ? false : undefined,
|
|
165
161
|
autoCapitalize: isEditable ? 'off' : undefined,
|
|
@@ -167,7 +163,7 @@ export function useFieldSectionContentProps(parameters) {
|
|
|
167
163
|
children: section.value || section.placeholder,
|
|
168
164
|
inputMode: section.contentType === 'letter' ? 'text' : 'numeric'
|
|
169
165
|
};
|
|
170
|
-
}, [sectionsValueBoundaries,
|
|
166
|
+
}, [sectionsValueBoundaries, isContainerEditable, disabled, readOnly, isEditable, translations, adapter, handleInput, handlePaste, handleMouseUp, handleDragOver, createFocusHandler, fieldValueManager, value]);
|
|
171
167
|
}
|
|
172
168
|
function getSectionValueText(section, adapter) {
|
|
173
169
|
if (!section.value) {
|
|
@@ -177,13 +173,18 @@ function getSectionValueText(section, adapter) {
|
|
|
177
173
|
case 'month':
|
|
178
174
|
{
|
|
179
175
|
if (section.contentType === 'digit') {
|
|
180
|
-
|
|
176
|
+
const dateWithMonth = adapter.setMonth(adapter.date(), Number(section.value) - 1);
|
|
177
|
+
return adapter.isValid(dateWithMonth) ? adapter.format(dateWithMonth, 'month') : '';
|
|
181
178
|
}
|
|
182
179
|
const parsedDate = adapter.parse(section.value, section.format);
|
|
183
|
-
return parsedDate ? adapter.format(parsedDate, 'month') : undefined;
|
|
180
|
+
return parsedDate && adapter.isValid(parsedDate) ? adapter.format(parsedDate, 'month') : undefined;
|
|
184
181
|
}
|
|
185
182
|
case 'day':
|
|
186
|
-
|
|
183
|
+
if (section.contentType === 'digit') {
|
|
184
|
+
const dateWithDay = adapter.setDate(adapter.startOfYear(adapter.date()), Number(section.value));
|
|
185
|
+
return adapter.isValid(dateWithDay) ? adapter.format(dateWithDay, 'dayOfMonthFull') : '';
|
|
186
|
+
}
|
|
187
|
+
return section.value;
|
|
187
188
|
case 'weekDay':
|
|
188
189
|
// TODO: improve by providing the label of the week day
|
|
189
190
|
return undefined;
|
|
@@ -8,7 +8,6 @@ import { PickersModalDialog } from "../../components/PickersModalDialog.js";
|
|
|
8
8
|
import { usePicker } from "../usePicker/index.js";
|
|
9
9
|
import { PickersLayout } from "../../../PickersLayout/index.js";
|
|
10
10
|
import { PickerProvider } from "../../components/PickerProvider.js";
|
|
11
|
-
import { PickerFieldUIContextProvider } from "../../components/PickerFieldUI.js";
|
|
12
11
|
import { createNonRangePickerStepNavigation } from "../../utils/createNonRangePickerStepNavigation.js";
|
|
13
12
|
|
|
14
13
|
/**
|
|
@@ -75,21 +74,20 @@ export const useMobilePicker = _ref => {
|
|
|
75
74
|
'aria-labelledby': labelledById
|
|
76
75
|
}, innerSlotProps?.mobilePaper)
|
|
77
76
|
});
|
|
78
|
-
const renderPicker = () => /*#__PURE__*/
|
|
79
|
-
children: /*#__PURE__*/
|
|
77
|
+
const renderPicker = () => /*#__PURE__*/_jsxs(PickerProvider, _extends({}, providerProps, {
|
|
78
|
+
children: [/*#__PURE__*/_jsx(Field, _extends({}, fieldProps, {
|
|
80
79
|
slots: slots,
|
|
81
80
|
slotProps: slotProps,
|
|
82
|
-
inputRef: inputRef
|
|
83
|
-
|
|
81
|
+
inputRef: inputRef
|
|
82
|
+
})), /*#__PURE__*/_jsx(PickersModalDialog, {
|
|
83
|
+
slots: slots,
|
|
84
|
+
slotProps: slotProps,
|
|
85
|
+
children: /*#__PURE__*/_jsx(Layout, _extends({}, slotProps?.layout, {
|
|
84
86
|
slots: slots,
|
|
85
87
|
slotProps: slotProps,
|
|
86
|
-
children:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
children: renderCurrentView()
|
|
90
|
-
}))
|
|
91
|
-
})]
|
|
92
|
-
})
|
|
88
|
+
children: renderCurrentView()
|
|
89
|
+
}))
|
|
90
|
+
})]
|
|
93
91
|
}));
|
|
94
92
|
if (process.env.NODE_ENV !== "production") renderPicker.displayName = "renderPicker";
|
|
95
93
|
return {
|
package/index.js
CHANGED
|
@@ -47,16 +47,6 @@ export interface ExportedPickerFieldUIProps {
|
|
|
47
47
|
openPickerButtonPosition?: 'start' | 'end';
|
|
48
48
|
}
|
|
49
49
|
export interface PickerFieldUIProps<TEnableAccessibleFieldDOMStructure extends boolean, TProps extends UseFieldProps<TEnableAccessibleFieldDOMStructure>> {
|
|
50
|
-
/**
|
|
51
|
-
* Overridable component slots.
|
|
52
|
-
* @default {}
|
|
53
|
-
*/
|
|
54
|
-
slots?: PickerFieldUISlots;
|
|
55
|
-
/**
|
|
56
|
-
* The props used for each component slot.
|
|
57
|
-
* @default {}
|
|
58
|
-
*/
|
|
59
|
-
slotProps?: PickerFieldUISlotProps;
|
|
60
50
|
/**
|
|
61
51
|
* Object returned by the `useField` hook or one of its wrapper (for example `useDateField`).
|
|
62
52
|
*/
|
|
@@ -21,6 +21,7 @@ var _resolveComponentProps = _interopRequireDefault(require("@mui/utils/resolveC
|
|
|
21
21
|
var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
|
|
22
22
|
var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
|
|
23
23
|
var _InputAdornment = _interopRequireDefault(require("@mui/material/InputAdornment"));
|
|
24
|
+
var _version = require("@mui/material/version");
|
|
24
25
|
var _useSlotProps5 = _interopRequireDefault(require("@mui/utils/useSlotProps"));
|
|
25
26
|
var _useFieldOwnerState = require("../hooks/useFieldOwnerState");
|
|
26
27
|
var _hooks = require("../../hooks");
|
|
@@ -36,6 +37,7 @@ const _excluded = ["enableAccessibleFieldDOMStructure"],
|
|
|
36
37
|
_excluded6 = ["ownerState"],
|
|
37
38
|
_excluded7 = ["ownerState"],
|
|
38
39
|
_excluded8 = ["InputProps", "inputProps"];
|
|
40
|
+
const noop = () => {};
|
|
39
41
|
const cleanFieldResponse = _ref => {
|
|
40
42
|
let {
|
|
41
43
|
enableAccessibleFieldDOMStructure
|
|
@@ -52,13 +54,20 @@ const cleanFieldResponse = _ref => {
|
|
|
52
54
|
openPickerAriaLabel
|
|
53
55
|
} = fieldResponse,
|
|
54
56
|
other = (0, _objectWithoutPropertiesLoose2.default)(fieldResponse, _excluded2);
|
|
57
|
+
const mergedInputProps = _version.major >= 6 && other?.slotProps?.input ? mergeSlotProps(other?.slotProps?.input, InputProps) : noop;
|
|
55
58
|
return {
|
|
56
59
|
clearable,
|
|
57
60
|
onClear,
|
|
58
61
|
clearButtonPosition,
|
|
59
62
|
openPickerButtonPosition,
|
|
60
63
|
openPickerAriaLabel,
|
|
61
|
-
textFieldProps: (0, _extends2.default)({}, other, {
|
|
64
|
+
textFieldProps: (0, _extends2.default)({}, other, _version.major >= 6 && other?.slotProps?.input ? {
|
|
65
|
+
slotProps: (0, _extends2.default)({}, other?.slotProps, {
|
|
66
|
+
input: ownerState => (0, _extends2.default)({}, (0, _resolveComponentProps.default)(mergedInputProps, ownerState), {
|
|
67
|
+
readOnly
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
} : {
|
|
62
71
|
InputProps: (0, _extends2.default)({}, InputProps ?? {}, {
|
|
63
72
|
readOnly
|
|
64
73
|
})
|
|
@@ -80,13 +89,27 @@ const cleanFieldResponse = _ref => {
|
|
|
80
89
|
openPickerAriaLabel
|
|
81
90
|
} = fieldResponse,
|
|
82
91
|
other = (0, _objectWithoutPropertiesLoose2.default)(fieldResponse, _excluded3);
|
|
92
|
+
const mergedInputProps = _version.major >= 6 && other?.slotProps?.input ? mergeSlotProps(other?.slotProps?.input, InputProps) : noop;
|
|
93
|
+
const mergedHtmlInputProps = _version.major >= 6 && other?.slotProps?.htmlInput ? mergeSlotProps(other?.slotProps?.htmlInput, inputProps) : noop;
|
|
83
94
|
return {
|
|
84
95
|
clearable,
|
|
85
96
|
onClear,
|
|
86
97
|
clearButtonPosition,
|
|
87
98
|
openPickerButtonPosition,
|
|
88
99
|
openPickerAriaLabel,
|
|
89
|
-
textFieldProps: (0, _extends2.default)({}, other, {
|
|
100
|
+
textFieldProps: (0, _extends2.default)({}, other, _version.major >= 6 && (other?.slotProps?.input || other?.slotProps?.htmlInput) ? {
|
|
101
|
+
slotProps: (0, _extends2.default)({}, other?.slotProps, {
|
|
102
|
+
input: ownerState => (0, _extends2.default)({}, (0, _resolveComponentProps.default)(mergedInputProps, ownerState), {
|
|
103
|
+
readOnly
|
|
104
|
+
}),
|
|
105
|
+
htmlInput: ownerState => (0, _extends2.default)({}, (0, _resolveComponentProps.default)(mergedHtmlInputProps, ownerState), {
|
|
106
|
+
inputMode,
|
|
107
|
+
onPaste,
|
|
108
|
+
onKeyDown,
|
|
109
|
+
ref: inputRef
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
} : {
|
|
90
113
|
InputProps: (0, _extends2.default)({}, InputProps ?? {}, {
|
|
91
114
|
readOnly
|
|
92
115
|
}),
|
|
@@ -113,8 +136,6 @@ const PickerFieldUIContext = exports.PickerFieldUIContext = /*#__PURE__*/React.c
|
|
|
113
136
|
if (process.env.NODE_ENV !== "production") PickerFieldUIContext.displayName = "PickerFieldUIContext";
|
|
114
137
|
function PickerFieldUI(props) {
|
|
115
138
|
const {
|
|
116
|
-
slots,
|
|
117
|
-
slotProps,
|
|
118
139
|
fieldResponse,
|
|
119
140
|
defaultOpenPickerIcon
|
|
120
141
|
} = props;
|
|
@@ -137,11 +158,11 @@ function PickerFieldUI(props) {
|
|
|
137
158
|
const triggerStatus = pickerContext ? pickerContext.triggerStatus : 'hidden';
|
|
138
159
|
const clearButtonPosition = clearable ? clearButtonPositionProp : null;
|
|
139
160
|
const openPickerButtonPosition = triggerStatus !== 'hidden' ? openPickerButtonPositionProp : null;
|
|
140
|
-
const TextField =
|
|
141
|
-
const InputAdornment =
|
|
161
|
+
const TextField = pickerFieldUIContext.slots.textField ?? (fieldResponse.enableAccessibleFieldDOMStructure === false ? _TextField.default : _PickersTextField.PickersTextField);
|
|
162
|
+
const InputAdornment = pickerFieldUIContext.slots.inputAdornment ?? _InputAdornment.default;
|
|
142
163
|
const _useSlotProps = (0, _useSlotProps5.default)({
|
|
143
164
|
elementType: InputAdornment,
|
|
144
|
-
externalSlotProps:
|
|
165
|
+
externalSlotProps: pickerFieldUIContext.slotProps.inputAdornment,
|
|
145
166
|
additionalProps: {
|
|
146
167
|
position: 'start'
|
|
147
168
|
},
|
|
@@ -152,7 +173,7 @@ function PickerFieldUI(props) {
|
|
|
152
173
|
startInputAdornmentProps = (0, _objectWithoutPropertiesLoose2.default)(_useSlotProps, _excluded4);
|
|
153
174
|
const _useSlotProps2 = (0, _useSlotProps5.default)({
|
|
154
175
|
elementType: InputAdornment,
|
|
155
|
-
externalSlotProps:
|
|
176
|
+
externalSlotProps: pickerFieldUIContext.slotProps.inputAdornment,
|
|
156
177
|
additionalProps: {
|
|
157
178
|
position: 'end'
|
|
158
179
|
},
|
|
@@ -183,11 +204,11 @@ function PickerFieldUI(props) {
|
|
|
183
204
|
externalSlotProps: pickerFieldUIContext.slotProps.openPickerIcon,
|
|
184
205
|
ownerState
|
|
185
206
|
});
|
|
186
|
-
const ClearButton =
|
|
207
|
+
const ClearButton = pickerFieldUIContext.slots.clearButton ?? _IconButton.default;
|
|
187
208
|
// We don't want to forward the `ownerState` to the `<IconButton />` component, see mui/material-ui#34056
|
|
188
209
|
const _useSlotProps4 = (0, _useSlotProps5.default)({
|
|
189
210
|
elementType: ClearButton,
|
|
190
|
-
externalSlotProps:
|
|
211
|
+
externalSlotProps: pickerFieldUIContext.slotProps.clearButton,
|
|
191
212
|
className: 'clearButton',
|
|
192
213
|
additionalProps: {
|
|
193
214
|
title: translations.fieldClearLabel,
|
|
@@ -201,24 +222,23 @@ function PickerFieldUI(props) {
|
|
|
201
222
|
ownerState
|
|
202
223
|
}),
|
|
203
224
|
clearButtonProps = (0, _objectWithoutPropertiesLoose2.default)(_useSlotProps4, _excluded7);
|
|
204
|
-
const ClearIcon =
|
|
225
|
+
const ClearIcon = pickerFieldUIContext.slots.clearIcon ?? _icons.ClearIcon;
|
|
205
226
|
const clearIconProps = (0, _useSlotProps5.default)({
|
|
206
227
|
elementType: ClearIcon,
|
|
207
|
-
externalSlotProps:
|
|
228
|
+
externalSlotProps: pickerFieldUIContext.slotProps.clearIcon,
|
|
208
229
|
additionalProps: {
|
|
209
230
|
fontSize: 'small'
|
|
210
231
|
},
|
|
211
232
|
ownerState
|
|
212
233
|
});
|
|
213
234
|
textFieldProps.ref = (0, _useForkRef.default)(textFieldProps.ref, pickerContext?.rootRef);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
235
|
+
const additionalTextFieldInputProps = {};
|
|
236
|
+
const textFieldInputProps = (0, _resolveComponentProps.default)((_version.major >= 6 && textFieldProps?.slotProps?.input) ?? textFieldProps.InputProps, ownerState);
|
|
217
237
|
if (pickerContext) {
|
|
218
|
-
|
|
238
|
+
additionalTextFieldInputProps.ref = pickerContext.triggerRef;
|
|
219
239
|
}
|
|
220
|
-
if (!
|
|
221
|
-
|
|
240
|
+
if (!textFieldInputProps?.startAdornment && (clearButtonPosition === 'start' || openPickerButtonPosition === 'start')) {
|
|
241
|
+
additionalTextFieldInputProps.startAdornment = /*#__PURE__*/(0, _jsxRuntime.jsxs)(InputAdornment, (0, _extends2.default)({}, startInputAdornmentProps, {
|
|
222
242
|
children: [openPickerButtonPosition === 'start' && /*#__PURE__*/(0, _jsxRuntime.jsx)(OpenPickerButton, (0, _extends2.default)({}, openPickerButtonProps, {
|
|
223
243
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(OpenPickerIcon, (0, _extends2.default)({}, openPickerIconProps))
|
|
224
244
|
})), clearButtonPosition === 'start' && /*#__PURE__*/(0, _jsxRuntime.jsx)(ClearButton, (0, _extends2.default)({}, clearButtonProps, {
|
|
@@ -226,8 +246,8 @@ function PickerFieldUI(props) {
|
|
|
226
246
|
}))]
|
|
227
247
|
}));
|
|
228
248
|
}
|
|
229
|
-
if (!
|
|
230
|
-
|
|
249
|
+
if (!textFieldInputProps?.endAdornment && (clearButtonPosition === 'end' || openPickerButtonPosition === 'end')) {
|
|
250
|
+
additionalTextFieldInputProps.endAdornment = /*#__PURE__*/(0, _jsxRuntime.jsxs)(InputAdornment, (0, _extends2.default)({}, endInputAdornmentProps, {
|
|
231
251
|
children: [clearButtonPosition === 'end' && /*#__PURE__*/(0, _jsxRuntime.jsx)(ClearButton, (0, _extends2.default)({}, clearButtonProps, {
|
|
232
252
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ClearIcon, (0, _extends2.default)({}, clearIconProps))
|
|
233
253
|
})), openPickerButtonPosition === 'end' && /*#__PURE__*/(0, _jsxRuntime.jsx)(OpenPickerButton, (0, _extends2.default)({}, openPickerButtonProps, {
|
|
@@ -235,6 +255,10 @@ function PickerFieldUI(props) {
|
|
|
235
255
|
}))]
|
|
236
256
|
}));
|
|
237
257
|
}
|
|
258
|
+
// handle the case of showing custom `inputAdornment` for Field components
|
|
259
|
+
if (!additionalTextFieldInputProps?.endAdornment && !additionalTextFieldInputProps?.startAdornment && pickerFieldUIContext.slots.inputAdornment) {
|
|
260
|
+
additionalTextFieldInputProps.endAdornment = /*#__PURE__*/(0, _jsxRuntime.jsx)(InputAdornment, (0, _extends2.default)({}, endInputAdornmentProps));
|
|
261
|
+
}
|
|
238
262
|
if (clearButtonPosition != null) {
|
|
239
263
|
textFieldProps.sx = [{
|
|
240
264
|
'& .clearButton': {
|
|
@@ -252,7 +276,18 @@ function PickerFieldUI(props) {
|
|
|
252
276
|
}
|
|
253
277
|
}, ...(Array.isArray(textFieldProps.sx) ? textFieldProps.sx : [textFieldProps.sx])];
|
|
254
278
|
}
|
|
255
|
-
|
|
279
|
+
const resolvedTextFieldInputProps = _version.major >= 6 && textFieldProps?.slotProps?.input ? (0, _resolveComponentProps.default)(mergeSlotProps(textFieldInputProps, additionalTextFieldInputProps), ownerState) : (0, _extends2.default)({}, textFieldInputProps, additionalTextFieldInputProps);
|
|
280
|
+
|
|
281
|
+
// Remove the `input` slotProps to avoid them overriding the manually resolved `InputProps`.
|
|
282
|
+
// Relevant on `materialMajor >= 6` since `slotProps` would take precedence.
|
|
283
|
+
delete textFieldProps?.slotProps?.input;
|
|
284
|
+
if (fieldResponse.enableAccessibleFieldDOMStructure) {
|
|
285
|
+
// Remove the `slotProps` on `PickersTextField` as they are not supported.
|
|
286
|
+
delete textFieldProps?.slotProps;
|
|
287
|
+
}
|
|
288
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(TextField, (0, _extends2.default)({}, textFieldProps, {
|
|
289
|
+
InputProps: resolvedTextFieldInputProps
|
|
290
|
+
}));
|
|
256
291
|
}
|
|
257
292
|
function mergeSlotProps(slotPropsA, slotPropsB) {
|
|
258
293
|
if (!slotPropsA) {
|
|
@@ -14,7 +14,6 @@ var _PickerPopper = require("../../components/PickerPopper/PickerPopper");
|
|
|
14
14
|
var _usePicker = require("../usePicker");
|
|
15
15
|
var _PickersLayout = require("../../../PickersLayout");
|
|
16
16
|
var _PickerProvider = require("../../components/PickerProvider");
|
|
17
|
-
var _PickerFieldUI = require("../../components/PickerFieldUI");
|
|
18
17
|
var _createNonRangePickerStepNavigation = require("../../utils/createNonRangePickerStepNavigation");
|
|
19
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
19
|
const _excluded = ["props", "steps"],
|
|
@@ -82,21 +81,20 @@ const useDesktopPicker = _ref => {
|
|
|
82
81
|
'aria-labelledby': labelledById
|
|
83
82
|
}, innerSlotProps?.popper)
|
|
84
83
|
});
|
|
85
|
-
const renderPicker = () => /*#__PURE__*/(0, _jsxRuntime.
|
|
86
|
-
children: /*#__PURE__*/(0, _jsxRuntime.
|
|
84
|
+
const renderPicker = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_PickerProvider.PickerProvider, (0, _extends2.default)({}, providerProps, {
|
|
85
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Field, (0, _extends2.default)({}, fieldProps, {
|
|
87
86
|
slots: slots,
|
|
88
87
|
slotProps: slotProps,
|
|
89
|
-
inputRef: inputRef
|
|
90
|
-
|
|
88
|
+
inputRef: inputRef
|
|
89
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickerPopper.PickerPopper, {
|
|
90
|
+
slots: slots,
|
|
91
|
+
slotProps: slotProps,
|
|
92
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Layout, (0, _extends2.default)({}, slotProps?.layout, {
|
|
91
93
|
slots: slots,
|
|
92
94
|
slotProps: slotProps,
|
|
93
|
-
children:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
children: renderCurrentView()
|
|
97
|
-
}))
|
|
98
|
-
})]
|
|
99
|
-
})
|
|
95
|
+
children: renderCurrentView()
|
|
96
|
+
}))
|
|
97
|
+
})]
|
|
100
98
|
}));
|
|
101
99
|
if (process.env.NODE_ENV !== "production") renderPicker.displayName = "renderPicker";
|
|
102
100
|
return {
|
|
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.useFieldSectionContentProps = useFieldSectionContentProps;
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
11
|
-
var _useId = _interopRequireDefault(require("@mui/utils/useId"));
|
|
12
11
|
var _hooks = require("../../../hooks");
|
|
13
12
|
var _syncSelectionToDOM = require("./syncSelectionToDOM");
|
|
14
13
|
/**
|
|
@@ -21,7 +20,6 @@ var _syncSelectionToDOM = require("./syncSelectionToDOM");
|
|
|
21
20
|
function useFieldSectionContentProps(parameters) {
|
|
22
21
|
const adapter = (0, _hooks.usePickerAdapter)();
|
|
23
22
|
const translations = (0, _hooks.usePickerTranslations)();
|
|
24
|
-
const id = (0, _useId.default)();
|
|
25
23
|
const {
|
|
26
24
|
focused,
|
|
27
25
|
domGetters,
|
|
@@ -155,7 +153,6 @@ function useFieldSectionContentProps(parameters) {
|
|
|
155
153
|
onDragOver: handleDragOver,
|
|
156
154
|
onFocus: createFocusHandler(sectionIndex),
|
|
157
155
|
// Aria attributes
|
|
158
|
-
'aria-labelledby': `${id}-${section.type}`,
|
|
159
156
|
'aria-readonly': readOnly,
|
|
160
157
|
'aria-valuenow': getSectionValueNow(section, adapter),
|
|
161
158
|
'aria-valuemin': sectionBoundaries.minimum,
|
|
@@ -167,7 +164,6 @@ function useFieldSectionContentProps(parameters) {
|
|
|
167
164
|
tabIndex: isContainerEditable || sectionIndex > 0 ? -1 : 0,
|
|
168
165
|
contentEditable: !isContainerEditable && !disabled && !readOnly,
|
|
169
166
|
role: 'spinbutton',
|
|
170
|
-
id: `${id}-${section.type}`,
|
|
171
167
|
'data-range-position': section.dateName || undefined,
|
|
172
168
|
spellCheck: isEditable ? false : undefined,
|
|
173
169
|
autoCapitalize: isEditable ? 'off' : undefined,
|
|
@@ -175,7 +171,7 @@ function useFieldSectionContentProps(parameters) {
|
|
|
175
171
|
children: section.value || section.placeholder,
|
|
176
172
|
inputMode: section.contentType === 'letter' ? 'text' : 'numeric'
|
|
177
173
|
};
|
|
178
|
-
}, [sectionsValueBoundaries,
|
|
174
|
+
}, [sectionsValueBoundaries, isContainerEditable, disabled, readOnly, isEditable, translations, adapter, handleInput, handlePaste, handleMouseUp, handleDragOver, createFocusHandler, fieldValueManager, value]);
|
|
179
175
|
}
|
|
180
176
|
function getSectionValueText(section, adapter) {
|
|
181
177
|
if (!section.value) {
|
|
@@ -185,13 +181,18 @@ function getSectionValueText(section, adapter) {
|
|
|
185
181
|
case 'month':
|
|
186
182
|
{
|
|
187
183
|
if (section.contentType === 'digit') {
|
|
188
|
-
|
|
184
|
+
const dateWithMonth = adapter.setMonth(adapter.date(), Number(section.value) - 1);
|
|
185
|
+
return adapter.isValid(dateWithMonth) ? adapter.format(dateWithMonth, 'month') : '';
|
|
189
186
|
}
|
|
190
187
|
const parsedDate = adapter.parse(section.value, section.format);
|
|
191
|
-
return parsedDate ? adapter.format(parsedDate, 'month') : undefined;
|
|
188
|
+
return parsedDate && adapter.isValid(parsedDate) ? adapter.format(parsedDate, 'month') : undefined;
|
|
192
189
|
}
|
|
193
190
|
case 'day':
|
|
194
|
-
|
|
191
|
+
if (section.contentType === 'digit') {
|
|
192
|
+
const dateWithDay = adapter.setDate(adapter.startOfYear(adapter.date()), Number(section.value));
|
|
193
|
+
return adapter.isValid(dateWithDay) ? adapter.format(dateWithDay, 'dayOfMonthFull') : '';
|
|
194
|
+
}
|
|
195
|
+
return section.value;
|
|
195
196
|
case 'weekDay':
|
|
196
197
|
// TODO: improve by providing the label of the week day
|
|
197
198
|
return undefined;
|