Skip to content

Commit

Permalink
[DateTimeRangePicker] Resolve format from given views (mui#13743)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasTy authored and DungTiger committed Jul 23, 2024
1 parent f053835 commit a81e05a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
isInternalTimeView,
PickerViewRenderer,
PickerViewsRendererProps,
resolveDateTimeFormat,
useUtils,
} from '@mui/x-date-pickers/internals';
import { PickerValidDate } from '@mui/x-date-pickers/models';
import { resolveComponentProps } from '@mui/base/utils';
Expand Down Expand Up @@ -138,6 +140,7 @@ const DesktopDateTimeRangePicker = React.forwardRef(function DesktopDateTimeRang
inProps: DesktopDateTimeRangePickerProps<TDate, TEnableAccessibleFieldDOMStructure>,
ref: React.Ref<HTMLDivElement>,
) {
const utils = useUtils<TDate>();
// Props with the default values common to all date time range pickers
const defaultizedProps = useDateTimeRangePickerDefaultizedProps<
TDate,
Expand Down Expand Up @@ -170,6 +173,7 @@ const DesktopDateTimeRangePicker = React.forwardRef(function DesktopDateTimeRang
...defaultizedProps,
views,
viewRenderers,
format: resolveDateTimeFormat(utils, defaultizedProps),
// force true to correctly handle `renderTimeViewClock` as a renderer
ampmInClock: true,
calendars: defaultizedProps.calendars ?? 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
DefaultizedProps,
PickerViewsRendererProps,
TimeViewWithMeridiem,
resolveDateTimeFormat,
useUtils,
} from '@mui/x-date-pickers/internals';
import { PickerValidDate } from '@mui/x-date-pickers/models';
import { resolveComponentProps } from '@mui/base/utils';
Expand Down Expand Up @@ -147,6 +149,7 @@ const MobileDateTimeRangePicker = React.forwardRef(function MobileDateTimeRangeP
inProps: MobileDateTimeRangePickerProps<TDate, TEnableAccessibleFieldDOMStructure>,
ref: React.Ref<HTMLDivElement>,
) {
const utils = useUtils<TDate>();
// Props with the default values common to all date time range pickers
const defaultizedProps = useDateTimeRangePickerDefaultizedProps<
TDate,
Expand All @@ -169,6 +172,7 @@ const MobileDateTimeRangePicker = React.forwardRef(function MobileDateTimeRangeP
const props = {
...defaultizedProps,
viewRenderers,
format: resolveDateTimeFormat(utils, defaultizedProps),
// Force one calendar on mobile to avoid layout issues
calendars: 1,
// force true to correctly handle `renderTimeViewClock` as a renderer
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/internals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export {
mergeDateAndTime,
formatMeridiem,
} from './utils/date-utils';
export { resolveTimeViewsResponse } from './utils/date-time-utils';
export { resolveTimeViewsResponse, resolveDateTimeFormat } from './utils/date-time-utils';
export { splitFieldInternalAndForwardedProps } from './utils/fields';
export { getDefaultReferenceDate } from './utils/getDefaultReferenceDate';
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { DefaultizedProps } from '../models/helpers';

export const resolveDateTimeFormat = <TDate extends PickerValidDate>(
utils: MuiPickersAdapter<TDate>,
{ views, format, ...other }: { format?: string; views: readonly DateOrTimeView[]; ampm: boolean },
{
views,
format,
...other
}: { format?: string; views: readonly DateOrTimeViewWithMeridiem[]; ampm: boolean },
) => {
if (format) {
return format;
Expand Down

0 comments on commit a81e05a

Please sign in to comment.