@mui/x-date-pickers 7.6.0 → 7.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AdapterDayjs/AdapterDayjs.js +5 -1
- package/CHANGELOG.md +91 -0
- package/DateCalendar/DayCalendar.js +11 -11
- package/DateTimePicker/DateTimePickerToolbar.js +59 -49
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +11 -1
- package/MonthCalendar/MonthCalendar.js +4 -4
- package/PickersLayout/PickersLayout.d.ts +1 -3
- package/PickersLayout/PickersLayout.js +30 -9
- package/PickersLayout/PickersLayout.types.d.ts +8 -4
- package/PickersTextField/PickersInputBase/PickersInputBase.d.ts +1 -0
- package/PickersTextField/PickersInputBase/PickersInputBase.js +14 -6
- package/TimePicker/TimePickerToolbar.js +21 -18
- package/YearCalendar/YearCalendar.js +4 -4
- package/index.js +1 -1
- package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +5 -5
- package/internals/components/PickersToolbarButton.d.ts +1 -1
- package/internals/hooks/useField/buildSectionsFromFormat.d.ts +1 -1
- package/internals/hooks/useField/buildSectionsFromFormat.js +3 -3
- package/internals/hooks/useField/useField.js +3 -4
- package/internals/hooks/useField/useField.types.d.ts +2 -2
- package/internals/hooks/useField/useField.utils.d.ts +1 -1
- package/internals/hooks/useField/useField.utils.js +6 -5
- package/internals/hooks/useField/useFieldState.js +6 -7
- package/internals/hooks/useField/useFieldV6TextField.d.ts +1 -1
- package/internals/hooks/useField/useFieldV6TextField.js +10 -11
- package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +1 -0
- package/internals/hooks/usePicker/usePickerLayoutProps.js +3 -0
- package/modern/AdapterDayjs/AdapterDayjs.js +5 -1
- package/modern/DateCalendar/DayCalendar.js +11 -11
- package/modern/DateTimePicker/DateTimePickerToolbar.js +59 -49
- package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +11 -1
- package/modern/MonthCalendar/MonthCalendar.js +4 -4
- package/modern/PickersLayout/PickersLayout.js +30 -9
- package/modern/PickersTextField/PickersInputBase/PickersInputBase.js +14 -6
- package/modern/TimePicker/TimePickerToolbar.js +21 -18
- package/modern/YearCalendar/YearCalendar.js +4 -4
- package/modern/index.js +1 -1
- package/modern/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +5 -5
- package/modern/internals/hooks/useField/buildSectionsFromFormat.js +3 -3
- package/modern/internals/hooks/useField/useField.js +3 -4
- package/modern/internals/hooks/useField/useField.utils.js +6 -5
- package/modern/internals/hooks/useField/useFieldState.js +6 -7
- package/modern/internals/hooks/useField/useFieldV6TextField.js +10 -11
- package/modern/internals/hooks/usePicker/usePickerLayoutProps.js +3 -0
- package/node/AdapterDayjs/AdapterDayjs.js +5 -1
- package/node/DateCalendar/DayCalendar.js +10 -10
- package/node/DateTimePicker/DateTimePickerToolbar.js +58 -48
- package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +11 -1
- package/node/MonthCalendar/MonthCalendar.js +4 -4
- package/node/PickersLayout/PickersLayout.js +30 -9
- package/node/PickersTextField/PickersInputBase/PickersInputBase.js +14 -6
- package/node/TimePicker/TimePickerToolbar.js +20 -17
- package/node/YearCalendar/YearCalendar.js +4 -4
- package/node/index.js +1 -1
- package/node/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +4 -4
- package/node/internals/hooks/useField/buildSectionsFromFormat.js +3 -3
- package/node/internals/hooks/useField/useField.js +3 -4
- package/node/internals/hooks/useField/useField.utils.js +6 -5
- package/node/internals/hooks/useField/useFieldState.js +6 -7
- package/node/internals/hooks/useField/useFieldV6TextField.js +10 -11
- package/node/internals/hooks/usePicker/usePickerLayoutProps.js +3 -0
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
const _excluded = ["ampm", "ampmInClock", "value", "isLandscape", "onChange", "view", "onViewChange", "views", "disabled", "readOnly", "className"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
|
-
import {
|
|
7
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
8
|
+
import { styled, useThemeProps } from '@mui/material/styles';
|
|
8
9
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
9
10
|
import { PickersToolbarText } from '../internals/components/PickersToolbarText';
|
|
10
11
|
import { PickersToolbarButton } from '../internals/components/PickersToolbarButton';
|
|
@@ -17,14 +18,14 @@ import { formatMeridiem } from '../internals/utils/date-utils';
|
|
|
17
18
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
19
|
const useUtilityClasses = ownerState => {
|
|
19
20
|
const {
|
|
20
|
-
theme,
|
|
21
21
|
isLandscape,
|
|
22
|
-
classes
|
|
22
|
+
classes,
|
|
23
|
+
isRtl
|
|
23
24
|
} = ownerState;
|
|
24
25
|
const slots = {
|
|
25
26
|
root: ['root'],
|
|
26
27
|
separator: ['separator'],
|
|
27
|
-
hourMinuteLabel: ['hourMinuteLabel', isLandscape && 'hourMinuteLabelLandscape',
|
|
28
|
+
hourMinuteLabel: ['hourMinuteLabel', isLandscape && 'hourMinuteLabelLandscape', isRtl && 'hourMinuteLabelReverse'],
|
|
28
29
|
ampmSelection: ['ampmSelection', isLandscape && 'ampmLandscape'],
|
|
29
30
|
ampmLabel: ['ampmLabel']
|
|
30
31
|
};
|
|
@@ -51,16 +52,18 @@ const TimePickerToolbarHourMinuteLabel = styled('div', {
|
|
|
51
52
|
[`&.${timePickerToolbarClasses.hourMinuteLabelLandscape}`]: styles.hourMinuteLabelLandscape,
|
|
52
53
|
[`&.${timePickerToolbarClasses.hourMinuteLabelReverse}`]: styles.hourMinuteLabelReverse
|
|
53
54
|
}, styles.hourMinuteLabel]
|
|
54
|
-
})(
|
|
55
|
-
theme
|
|
56
|
-
}) => _extends({
|
|
55
|
+
})({
|
|
57
56
|
display: 'flex',
|
|
58
57
|
justifyContent: 'flex-end',
|
|
59
|
-
alignItems: 'flex-end'
|
|
60
|
-
}, theme.direction === 'rtl' && {
|
|
61
|
-
flexDirection: 'row-reverse'
|
|
62
|
-
}, {
|
|
58
|
+
alignItems: 'flex-end',
|
|
63
59
|
variants: [{
|
|
60
|
+
props: {
|
|
61
|
+
isRtl: true
|
|
62
|
+
},
|
|
63
|
+
style: {
|
|
64
|
+
flexDirection: 'row-reverse'
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
64
67
|
props: {
|
|
65
68
|
isLandscape: true
|
|
66
69
|
},
|
|
@@ -68,7 +71,7 @@ const TimePickerToolbarHourMinuteLabel = styled('div', {
|
|
|
68
71
|
marginTop: 'auto'
|
|
69
72
|
}
|
|
70
73
|
}]
|
|
71
|
-
})
|
|
74
|
+
});
|
|
72
75
|
const TimePickerToolbarAmPmSelection = styled('div', {
|
|
73
76
|
name: 'MuiTimePickerToolbar',
|
|
74
77
|
slot: 'AmPmSelection',
|
|
@@ -129,17 +132,17 @@ function TimePickerToolbar(inProps) {
|
|
|
129
132
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
130
133
|
const utils = useUtils();
|
|
131
134
|
const localeText = useLocaleText();
|
|
132
|
-
const
|
|
135
|
+
const isRtl = useRtl();
|
|
133
136
|
const showAmPmControl = Boolean(ampm && !ampmInClock && views.includes('hours'));
|
|
134
137
|
const {
|
|
135
138
|
meridiemMode,
|
|
136
139
|
handleMeridiemChange
|
|
137
140
|
} = useMeridiemMode(value, ampm, onChange);
|
|
138
141
|
const formatHours = time => ampm ? utils.format(time, 'hours12h') : utils.format(time, 'hours24h');
|
|
139
|
-
const ownerState = props
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
const ownerState = _extends({}, props, {
|
|
143
|
+
isRtl
|
|
144
|
+
});
|
|
145
|
+
const classes = useUtilityClasses(ownerState);
|
|
143
146
|
const separator = /*#__PURE__*/_jsx(TimePickerToolbarSeparator, {
|
|
144
147
|
tabIndex: -1,
|
|
145
148
|
value: ":",
|
|
@@ -4,7 +4,7 @@ const _excluded = ["autoFocus", "className", "value", "defaultValue", "reference
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
|
-
import {
|
|
7
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
8
8
|
import { styled, useThemeProps } from '@mui/material/styles';
|
|
9
9
|
import { unstable_useForkRef as useForkRef, unstable_composeClasses as composeClasses, unstable_useControlled as useControlled, unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
10
10
|
import { PickersYear } from './PickersYear';
|
|
@@ -104,7 +104,7 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
|
|
|
104
104
|
valueManager: singleItemValueManager
|
|
105
105
|
});
|
|
106
106
|
const now = useNow(timezone);
|
|
107
|
-
const
|
|
107
|
+
const isRtl = useRtl();
|
|
108
108
|
const utils = useUtils();
|
|
109
109
|
const referenceDate = React.useMemo(() => singleItemValueManager.getInitialReferenceValue({
|
|
110
110
|
value,
|
|
@@ -184,11 +184,11 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
|
|
|
184
184
|
event.preventDefault();
|
|
185
185
|
break;
|
|
186
186
|
case 'ArrowLeft':
|
|
187
|
-
focusYear(year + (
|
|
187
|
+
focusYear(year + (isRtl ? 1 : -1));
|
|
188
188
|
event.preventDefault();
|
|
189
189
|
break;
|
|
190
190
|
case 'ArrowRight':
|
|
191
|
-
focusYear(year + (
|
|
191
|
+
focusYear(year + (isRtl ? -1 : 1));
|
|
192
192
|
event.preventDefault();
|
|
193
193
|
break;
|
|
194
194
|
default:
|
package/index.js
CHANGED
|
@@ -6,7 +6,8 @@ const _excluded = ["children", "className", "slots", "slotProps", "isNextDisable
|
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import clsx from 'clsx';
|
|
8
8
|
import Typography from '@mui/material/Typography';
|
|
9
|
-
import {
|
|
9
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
10
|
+
import { styled, useThemeProps } from '@mui/material/styles';
|
|
10
11
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
11
12
|
import { useSlotProps } from '@mui/base/utils';
|
|
12
13
|
import IconButton from '@mui/material/IconButton';
|
|
@@ -55,8 +56,7 @@ const useUtilityClasses = ownerState => {
|
|
|
55
56
|
return composeClasses(slots, getPickersArrowSwitcherUtilityClass, classes);
|
|
56
57
|
};
|
|
57
58
|
export const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function PickersArrowSwitcher(inProps, ref) {
|
|
58
|
-
const
|
|
59
|
-
const isRTL = theme.direction === 'rtl';
|
|
59
|
+
const isRtl = useRtl();
|
|
60
60
|
const props = useThemeProps({
|
|
61
61
|
props: inProps,
|
|
62
62
|
name: 'MuiPickersArrowSwitcher'
|
|
@@ -152,7 +152,7 @@ export const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function Picke
|
|
|
152
152
|
ownerState: ownerState
|
|
153
153
|
}, other, {
|
|
154
154
|
children: [/*#__PURE__*/_jsx(PreviousIconButton, _extends({}, previousIconButtonProps, {
|
|
155
|
-
children:
|
|
155
|
+
children: isRtl ? /*#__PURE__*/_jsx(RightArrowIcon, _extends({}, rightArrowIconProps)) : /*#__PURE__*/_jsx(LeftArrowIcon, _extends({}, leftArrowIconProps))
|
|
156
156
|
})), children ? /*#__PURE__*/_jsx(Typography, {
|
|
157
157
|
variant: "subtitle1",
|
|
158
158
|
component: "span",
|
|
@@ -161,7 +161,7 @@ export const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function Picke
|
|
|
161
161
|
className: classes.spacer,
|
|
162
162
|
ownerState: ownerState
|
|
163
163
|
}), /*#__PURE__*/_jsx(NextIconButton, _extends({}, nextIconButtonProps, {
|
|
164
|
-
children:
|
|
164
|
+
children: isRtl ? /*#__PURE__*/_jsx(LeftArrowIcon, _extends({}, leftArrowIconProps)) : /*#__PURE__*/_jsx(RightArrowIcon, _extends({}, rightArrowIconProps))
|
|
165
165
|
}))]
|
|
166
166
|
}));
|
|
167
167
|
});
|
|
@@ -12,4 +12,4 @@ export interface PickersToolbarButtonProps extends ExtendMui<ButtonProps, 'value
|
|
|
12
12
|
classes?: Partial<PickersToolbarButtonClasses>;
|
|
13
13
|
width?: number;
|
|
14
14
|
}
|
|
15
|
-
export declare const PickersToolbarButton: React.
|
|
15
|
+
export declare const PickersToolbarButton: React.ForwardRefExoticComponent<Omit<PickersToolbarButtonProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -4,7 +4,7 @@ interface BuildSectionsFromFormatParams<TDate extends PickerValidDate> {
|
|
|
4
4
|
utils: MuiPickersAdapter<TDate>;
|
|
5
5
|
format: string;
|
|
6
6
|
formatDensity: 'dense' | 'spacious';
|
|
7
|
-
|
|
7
|
+
isRtl: boolean;
|
|
8
8
|
timezone: PickersTimezone;
|
|
9
9
|
shouldRespectLeadingZeros: boolean;
|
|
10
10
|
localeText: PickersLocaleText<TDate>;
|
|
@@ -217,14 +217,14 @@ const buildSections = params => {
|
|
|
217
217
|
return sections;
|
|
218
218
|
};
|
|
219
219
|
const postProcessSections = ({
|
|
220
|
-
|
|
220
|
+
isRtl,
|
|
221
221
|
formatDensity,
|
|
222
222
|
sections
|
|
223
223
|
}) => {
|
|
224
224
|
return sections.map(section => {
|
|
225
225
|
const cleanSeparator = separator => {
|
|
226
226
|
let cleanedSeparator = separator;
|
|
227
|
-
if (
|
|
227
|
+
if (isRtl && cleanedSeparator !== null && cleanedSeparator.includes(' ')) {
|
|
228
228
|
cleanedSeparator = `\u2069${cleanedSeparator}\u2066`;
|
|
229
229
|
}
|
|
230
230
|
if (formatDensity === 'spacious' && ['/', '.', '-'].includes(cleanedSeparator)) {
|
|
@@ -239,7 +239,7 @@ const postProcessSections = ({
|
|
|
239
239
|
};
|
|
240
240
|
export const buildSectionsFromFormat = params => {
|
|
241
241
|
let expandedFormat = expandFormat(params);
|
|
242
|
-
if (params.
|
|
242
|
+
if (params.isRtl && params.enableAccessibleFieldDOMStructure) {
|
|
243
243
|
expandedFormat = expandedFormat.split(' ').reverse().join(' ');
|
|
244
244
|
}
|
|
245
245
|
const escapedParts = getEscapedPartsFromFormat(_extends({}, params, {
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
4
4
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
5
|
-
import {
|
|
5
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
6
6
|
import { useValidation } from '../useValidation';
|
|
7
7
|
import { useUtils } from '../useUtils';
|
|
8
8
|
import { adjustSectionValue, getSectionOrder } from './useField.utils';
|
|
@@ -31,8 +31,7 @@ export const useField = params => {
|
|
|
31
31
|
valueManager,
|
|
32
32
|
validator
|
|
33
33
|
} = params;
|
|
34
|
-
const
|
|
35
|
-
const isRTL = theme.direction === 'rtl';
|
|
34
|
+
const isRtl = useRtl();
|
|
36
35
|
const stateResponse = useFieldState(params);
|
|
37
36
|
const {
|
|
38
37
|
state,
|
|
@@ -60,7 +59,7 @@ export const useField = params => {
|
|
|
60
59
|
} = characterEditingResponse;
|
|
61
60
|
const areAllSectionsEmpty = valueManager.areValuesEqual(utils, state.value, valueManager.emptyValue);
|
|
62
61
|
const useFieldTextField = enableAccessibleFieldDOMStructure ? useFieldV7TextField : useFieldV6TextField;
|
|
63
|
-
const sectionOrder = React.useMemo(() => getSectionOrder(state.sections,
|
|
62
|
+
const sectionOrder = React.useMemo(() => getSectionOrder(state.sections, isRtl && !enableAccessibleFieldDOMStructure), [state.sections, isRtl, enableAccessibleFieldDOMStructure]);
|
|
64
63
|
const {
|
|
65
64
|
returnedValue,
|
|
66
65
|
interactions
|
|
@@ -220,10 +220,10 @@ export interface FieldValueManager<TValue, TDate extends PickerValidDate, TSecti
|
|
|
220
220
|
* @template TSection
|
|
221
221
|
* @param {TSection[]} sections The current section list.
|
|
222
222
|
* @param {string} localizedDigits The conversion table from localized to 0-9 digits.
|
|
223
|
-
* @param {boolean}
|
|
223
|
+
* @param {boolean} isRtl `true` if the current orientation is "right to left"
|
|
224
224
|
* @returns {string} The string value to render in the input.
|
|
225
225
|
*/
|
|
226
|
-
getV6InputValueFromSections: (sections: TSection[], localizedDigits: string[],
|
|
226
|
+
getV6InputValueFromSections: (sections: TSection[], localizedDigits: string[], isRtl: boolean) => string;
|
|
227
227
|
/**
|
|
228
228
|
* Creates the string value to render in the input based on the current section list.
|
|
229
229
|
* @template TSection
|
|
@@ -29,7 +29,7 @@ export declare const doesSectionFormatHaveLeadingZeros: <TDate extends PickerVal
|
|
|
29
29
|
*/
|
|
30
30
|
export declare const getDateFromDateSections: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, sections: FieldSection[], localizedDigits: string[]) => TDate;
|
|
31
31
|
export declare const createDateStrForV7HiddenInputFromSections: (sections: FieldSection[]) => string;
|
|
32
|
-
export declare const createDateStrForV6InputFromSections: (sections: FieldSection[], localizedDigits: string[],
|
|
32
|
+
export declare const createDateStrForV6InputFromSections: (sections: FieldSection[], localizedDigits: string[], isRtl: boolean) => string;
|
|
33
33
|
export declare const getSectionsBoundaries: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, localizedDigits: string[], timezone: PickersTimezone) => FieldSectionsValueBoundaries<TDate>;
|
|
34
34
|
export declare const validateSections: <TSection extends FieldSection>(sections: TSection[], valueType: FieldValueType) => void;
|
|
35
35
|
export declare const mergeDateIntoReferenceDate: <TDate extends PickerValidDate>(utils: MuiPickersAdapter<TDate>, timezone: PickersTimezone, dateToTransferFrom: TDate, sections: FieldSection[], referenceDate: TDate, shouldLimitToEditedSections: boolean) => TDate;
|
|
@@ -195,8 +195,9 @@ export const adjustSectionValue = (utils, timezone, section, keyCode, sectionsVa
|
|
|
195
195
|
return options[options.length - 1];
|
|
196
196
|
}
|
|
197
197
|
const currentOptionIndex = options.indexOf(section.value);
|
|
198
|
-
const newOptionIndex = (currentOptionIndex +
|
|
199
|
-
|
|
198
|
+
const newOptionIndex = (currentOptionIndex + delta) % options.length;
|
|
199
|
+
const clampedIndex = (newOptionIndex + options.length) % options.length;
|
|
200
|
+
return options[clampedIndex];
|
|
200
201
|
};
|
|
201
202
|
if (section.contentType === 'digit' || section.contentType === 'digit-with-letter') {
|
|
202
203
|
return adjustDigitSection();
|
|
@@ -306,13 +307,13 @@ export const getDateFromDateSections = (utils, sections, localizedDigits) => {
|
|
|
306
307
|
export const createDateStrForV7HiddenInputFromSections = sections => sections.map(section => {
|
|
307
308
|
return `${section.startSeparator}${section.value || section.placeholder}${section.endSeparator}`;
|
|
308
309
|
}).join('');
|
|
309
|
-
export const createDateStrForV6InputFromSections = (sections, localizedDigits,
|
|
310
|
+
export const createDateStrForV6InputFromSections = (sections, localizedDigits, isRtl) => {
|
|
310
311
|
const formattedSections = sections.map(section => {
|
|
311
|
-
const dateValue = getSectionVisibleValue(section,
|
|
312
|
+
const dateValue = getSectionVisibleValue(section, isRtl ? 'input-rtl' : 'input-ltr', localizedDigits);
|
|
312
313
|
return `${section.startSeparator}${dateValue}${section.endSeparator}`;
|
|
313
314
|
});
|
|
314
315
|
const dateStr = formattedSections.join('');
|
|
315
|
-
if (!
|
|
316
|
+
if (!isRtl) {
|
|
316
317
|
return dateStr;
|
|
317
318
|
}
|
|
318
319
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import useControlled from '@mui/utils/useControlled';
|
|
4
|
-
import {
|
|
4
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
5
5
|
import { useUtils, useLocaleText, useLocalizationContext } from '../useUtils';
|
|
6
6
|
import { mergeDateIntoReferenceDate, getSectionsBoundaries, validateSections, getDateFromDateSections, parseSelectedSections, getLocalizedDigits } from './useField.utils';
|
|
7
7
|
import { buildSectionsFromFormat } from './buildSectionsFromFormat';
|
|
@@ -11,8 +11,7 @@ export const useFieldState = params => {
|
|
|
11
11
|
const utils = useUtils();
|
|
12
12
|
const localeText = useLocaleText();
|
|
13
13
|
const adapter = useLocalizationContext();
|
|
14
|
-
const
|
|
15
|
-
const isRTL = theme.direction === 'rtl';
|
|
14
|
+
const isRtl = useRtl();
|
|
16
15
|
const {
|
|
17
16
|
valueManager,
|
|
18
17
|
fieldValueManager,
|
|
@@ -56,8 +55,8 @@ export const useFieldState = params => {
|
|
|
56
55
|
formatDensity,
|
|
57
56
|
shouldRespectLeadingZeros,
|
|
58
57
|
enableAccessibleFieldDOMStructure,
|
|
59
|
-
|
|
60
|
-
})), [fieldValueManager, format, localeText, localizedDigits,
|
|
58
|
+
isRtl
|
|
59
|
+
})), [fieldValueManager, format, localeText, localizedDigits, isRtl, shouldRespectLeadingZeros, utils, formatDensity, timezone, enableAccessibleFieldDOMStructure]);
|
|
61
60
|
const [state, setState] = React.useState(() => {
|
|
62
61
|
const sections = getSectionsFromValue(valueFromTheOutside);
|
|
63
62
|
validateSections(sections, valueType);
|
|
@@ -164,7 +163,7 @@ export const useFieldState = params => {
|
|
|
164
163
|
formatDensity,
|
|
165
164
|
shouldRespectLeadingZeros,
|
|
166
165
|
enableAccessibleFieldDOMStructure,
|
|
167
|
-
|
|
166
|
+
isRtl
|
|
168
167
|
});
|
|
169
168
|
return mergeDateIntoReferenceDate(utils, timezone, date, sections, referenceDate, false);
|
|
170
169
|
};
|
|
@@ -234,7 +233,7 @@ export const useFieldState = params => {
|
|
|
234
233
|
setState(prevState => _extends({}, prevState, {
|
|
235
234
|
sections
|
|
236
235
|
}));
|
|
237
|
-
}, [format, utils.locale,
|
|
236
|
+
}, [format, utils.locale, isRtl]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
238
237
|
|
|
239
238
|
React.useEffect(() => {
|
|
240
239
|
let shouldUpdate;
|
|
@@ -20,6 +20,6 @@ type FieldSectionWithPositions<TSection> = TSection & {
|
|
|
20
20
|
*/
|
|
21
21
|
endInInput: number;
|
|
22
22
|
};
|
|
23
|
-
export declare const addPositionPropertiesToSections: <TSection extends FieldSection>(sections: TSection[], localizedDigits: string[],
|
|
23
|
+
export declare const addPositionPropertiesToSections: <TSection extends FieldSection>(sections: TSection[], localizedDigits: string[], isRtl: boolean) => FieldSectionWithPositions<TSection>[];
|
|
24
24
|
export declare const useFieldV6TextField: UseFieldTextField<false>;
|
|
25
25
|
export {};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
4
4
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
5
5
|
import useForkRef from '@mui/utils/useForkRef';
|
|
6
6
|
import { getActiveElement } from '../../utils/utils';
|
|
7
7
|
import { getSectionVisibleValue, isAndroid } from './useField.utils';
|
|
8
8
|
const cleanString = dirtyString => dirtyString.replace(/[\u2066\u2067\u2068\u2069]/g, '');
|
|
9
|
-
export const addPositionPropertiesToSections = (sections, localizedDigits,
|
|
9
|
+
export const addPositionPropertiesToSections = (sections, localizedDigits, isRtl) => {
|
|
10
10
|
let position = 0;
|
|
11
|
-
let positionInInput =
|
|
11
|
+
let positionInInput = isRtl ? 1 : 0;
|
|
12
12
|
const newSections = [];
|
|
13
13
|
for (let i = 0; i < sections.length; i += 1) {
|
|
14
14
|
const section = sections[i];
|
|
15
|
-
const renderedValue = getSectionVisibleValue(section,
|
|
15
|
+
const renderedValue = getSectionVisibleValue(section, isRtl ? 'input-rtl' : 'input-ltr', localizedDigits);
|
|
16
16
|
const sectionStr = `${section.startSeparator}${renderedValue}${section.endSeparator}`;
|
|
17
17
|
const sectionLength = cleanString(sectionStr).length;
|
|
18
18
|
const sectionLengthInInput = sectionStr.length;
|
|
@@ -34,8 +34,7 @@ export const addPositionPropertiesToSections = (sections, localizedDigits, isRTL
|
|
|
34
34
|
return newSections;
|
|
35
35
|
};
|
|
36
36
|
export const useFieldV6TextField = params => {
|
|
37
|
-
const
|
|
38
|
-
const isRTL = theme.direction === 'rtl';
|
|
37
|
+
const isRtl = useRtl();
|
|
39
38
|
const focusTimeoutRef = React.useRef();
|
|
40
39
|
const {
|
|
41
40
|
forwardedProps: {
|
|
@@ -68,7 +67,7 @@ export const useFieldV6TextField = params => {
|
|
|
68
67
|
} = params;
|
|
69
68
|
const inputRef = React.useRef(null);
|
|
70
69
|
const handleRef = useForkRef(inputRefProp, inputRef);
|
|
71
|
-
const sections = React.useMemo(() => addPositionPropertiesToSections(state.sections, localizedDigits,
|
|
70
|
+
const sections = React.useMemo(() => addPositionPropertiesToSections(state.sections, localizedDigits, isRtl), [state.sections, localizedDigits, isRtl]);
|
|
72
71
|
const interactions = React.useMemo(() => ({
|
|
73
72
|
syncSelectionToDOM: () => {
|
|
74
73
|
if (!inputRef.current) {
|
|
@@ -241,7 +240,7 @@ export const useFieldV6TextField = params => {
|
|
|
241
240
|
if (parsedSelectedSections === 'all' && cleanValueStr.length === 1) {
|
|
242
241
|
keyPressed = cleanValueStr;
|
|
243
242
|
} else {
|
|
244
|
-
const prevValueStr = cleanString(fieldValueManager.getV6InputValueFromSections(sections, localizedDigits,
|
|
243
|
+
const prevValueStr = cleanString(fieldValueManager.getV6InputValueFromSections(sections, localizedDigits, isRtl));
|
|
245
244
|
let startOfDiffIndex = -1;
|
|
246
245
|
let endOfDiffIndex = -1;
|
|
247
246
|
for (let i = 0; i < prevValueStr.length; i += 1) {
|
|
@@ -281,9 +280,9 @@ export const useFieldV6TextField = params => {
|
|
|
281
280
|
if (inPlaceholder !== undefined) {
|
|
282
281
|
return inPlaceholder;
|
|
283
282
|
}
|
|
284
|
-
return fieldValueManager.getV6InputValueFromSections(getSectionsFromValue(valueManager.emptyValue), localizedDigits,
|
|
285
|
-
}, [inPlaceholder, fieldValueManager, getSectionsFromValue, valueManager.emptyValue, localizedDigits,
|
|
286
|
-
const valueStr = React.useMemo(() => state.tempValueStrAndroid ?? fieldValueManager.getV6InputValueFromSections(state.sections, localizedDigits,
|
|
283
|
+
return fieldValueManager.getV6InputValueFromSections(getSectionsFromValue(valueManager.emptyValue), localizedDigits, isRtl);
|
|
284
|
+
}, [inPlaceholder, fieldValueManager, getSectionsFromValue, valueManager.emptyValue, localizedDigits, isRtl]);
|
|
285
|
+
const valueStr = React.useMemo(() => state.tempValueStrAndroid ?? fieldValueManager.getV6InputValueFromSections(state.sections, localizedDigits, isRtl), [state.sections, fieldValueManager, state.tempValueStrAndroid, localizedDigits, isRtl]);
|
|
287
286
|
React.useEffect(() => {
|
|
288
287
|
// Select all the sections when focused on mount (`autoFocus = true` on the input)
|
|
289
288
|
if (inputRef.current && inputRef.current === getActiveElement(document)) {
|
|
@@ -15,6 +15,7 @@ export interface UsePickerLayoutProps {
|
|
|
15
15
|
}
|
|
16
16
|
export interface UsePickerLayoutPropsResponseLayoutProps<TValue, TView extends DateOrTimeViewWithMeridiem> extends UsePickerValueLayoutResponse<TValue>, UsePickerViewsLayoutResponse<TView>, UsePickerLayoutProps {
|
|
17
17
|
isLandscape: boolean;
|
|
18
|
+
isRtl: boolean;
|
|
18
19
|
wrapperVariant: WrapperVariant;
|
|
19
20
|
isValid: (value: TValue) => boolean;
|
|
20
21
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
2
3
|
import { useIsLandscape } from '../useIsLandscape';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -19,8 +20,10 @@ export const usePickerLayoutProps = ({
|
|
|
19
20
|
orientation
|
|
20
21
|
} = props;
|
|
21
22
|
const isLandscape = useIsLandscape(propsFromPickerViews.views, orientation);
|
|
23
|
+
const isRtl = useRtl();
|
|
22
24
|
const layoutProps = _extends({}, propsFromPickerViews, propsFromPickerValue, {
|
|
23
25
|
isLandscape,
|
|
26
|
+
isRtl,
|
|
24
27
|
wrapperVariant,
|
|
25
28
|
disabled: props.disabled,
|
|
26
29
|
readOnly: props.readOnly
|
|
@@ -256,7 +256,11 @@ export class AdapterDayjs {
|
|
|
256
256
|
if ((fixedValue.$offset ?? 0) === (value.$offset ?? 0)) {
|
|
257
257
|
return value;
|
|
258
258
|
}
|
|
259
|
-
|
|
259
|
+
// Change only what is needed to avoid creating a new object with unwanted data
|
|
260
|
+
// Especially important when used in an environment where utc or timezone dates are used only in some places
|
|
261
|
+
// Reference: https://github.com/mui/mui-x/issues/13290
|
|
262
|
+
// @ts-ignore
|
|
263
|
+
value.$offset = fixedValue.$offset;
|
|
260
264
|
}
|
|
261
265
|
return value;
|
|
262
266
|
};
|
|
@@ -6,7 +6,8 @@ import * as React from 'react';
|
|
|
6
6
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
7
7
|
import Typography from '@mui/material/Typography';
|
|
8
8
|
import { useSlotProps } from '@mui/base/utils';
|
|
9
|
-
import {
|
|
9
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
10
|
+
import { styled, useThemeProps } from '@mui/material/styles';
|
|
10
11
|
import { unstable_composeClasses as composeClasses, unstable_useControlled as useControlled } from '@mui/utils';
|
|
11
12
|
import clsx from 'clsx';
|
|
12
13
|
import { PickersDay } from '../PickersDay/PickersDay';
|
|
@@ -249,8 +250,7 @@ export function DayCalendar(inProps) {
|
|
|
249
250
|
} = props;
|
|
250
251
|
const now = useNow(timezone);
|
|
251
252
|
const classes = useUtilityClasses(props);
|
|
252
|
-
const
|
|
253
|
-
const isRTL = theme.direction === 'rtl';
|
|
253
|
+
const isRtl = useRtl();
|
|
254
254
|
const isDateDisabled = useIsDateDisabled({
|
|
255
255
|
shouldDisableDate,
|
|
256
256
|
shouldDisableMonth,
|
|
@@ -295,13 +295,13 @@ export function DayCalendar(inProps) {
|
|
|
295
295
|
break;
|
|
296
296
|
case 'ArrowLeft':
|
|
297
297
|
{
|
|
298
|
-
const newFocusedDayDefault = utils.addDays(day,
|
|
299
|
-
const nextAvailableMonth = utils.addMonths(day,
|
|
298
|
+
const newFocusedDayDefault = utils.addDays(day, isRtl ? 1 : -1);
|
|
299
|
+
const nextAvailableMonth = utils.addMonths(day, isRtl ? 1 : -1);
|
|
300
300
|
const closestDayToFocus = findClosestEnabledDate({
|
|
301
301
|
utils,
|
|
302
302
|
date: newFocusedDayDefault,
|
|
303
|
-
minDate:
|
|
304
|
-
maxDate:
|
|
303
|
+
minDate: isRtl ? newFocusedDayDefault : utils.startOfMonth(nextAvailableMonth),
|
|
304
|
+
maxDate: isRtl ? utils.endOfMonth(nextAvailableMonth) : newFocusedDayDefault,
|
|
305
305
|
isDateDisabled,
|
|
306
306
|
timezone
|
|
307
307
|
});
|
|
@@ -311,13 +311,13 @@ export function DayCalendar(inProps) {
|
|
|
311
311
|
}
|
|
312
312
|
case 'ArrowRight':
|
|
313
313
|
{
|
|
314
|
-
const newFocusedDayDefault = utils.addDays(day,
|
|
315
|
-
const nextAvailableMonth = utils.addMonths(day,
|
|
314
|
+
const newFocusedDayDefault = utils.addDays(day, isRtl ? -1 : 1);
|
|
315
|
+
const nextAvailableMonth = utils.addMonths(day, isRtl ? -1 : 1);
|
|
316
316
|
const closestDayToFocus = findClosestEnabledDate({
|
|
317
317
|
utils,
|
|
318
318
|
date: newFocusedDayDefault,
|
|
319
|
-
minDate:
|
|
320
|
-
maxDate:
|
|
319
|
+
minDate: isRtl ? utils.startOfMonth(nextAvailableMonth) : newFocusedDayDefault,
|
|
320
|
+
maxDate: isRtl ? newFocusedDayDefault : utils.endOfMonth(nextAvailableMonth),
|
|
321
321
|
isDateDisabled,
|
|
322
322
|
timezone
|
|
323
323
|
});
|