Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DateTimeRangePicker] Resolve format from given views #13743

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading