Skip to Content
Piplup
@piplup/rhf-adaptersmui-x-date-pickersHooks

useMuiXDateTimePickerAdapter

Returns adapter props for MUI X DateTimePicker with React Hook Form, including time rules such as minTime, maxTime, minutesStep and shouldDisableTime.

useMuiXDateTimePickerAdapter connects a field to React Hook Form and returns props you spread onto MUI X's DateTimePicker. It's what MuiXDateTimePickerElement uses internally.

Use the element for most forms. Use the hook when one kind of date-time field repeats across your app with the same rules, such as booking slots limited to opening hours, and you want those rules and messages defined once in your own component.

Import

import { useMuiXDateTimePickerAdapter } from '@piplup/rhf-adapters/mui-x-date-pickers';

Usage

This MeetingField accepts times from 09:00 to 17:00 in 15 minute steps, on any day from tomorrow. Type a time such as 08:30 or 10:07 and submit to see the time rules.

MM/DD/YYYY hh:mm

From tomorrow, 09:00 to 17:00

'use client';import Stack from '@mui/material/Stack';import { DateTimePicker, LocalizationProvider } from '@mui/x-date-pickers';import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';import { MuiButtonElement } from '@piplup/rhf-adapters/mui-material';import { useMuiXDateTimePickerAdapter } from '@piplup/rhf-adapters/mui-x-date-pickers';import dayjs from 'dayjs';import { useForm } from 'react-hook-form';import type { Dayjs } from 'dayjs';import type { Control } from 'react-hook-form';type FormValues = { meeting: Dayjs | null };// Office hours: 09:00 to 17:00 on any day, in 15 minute slots, booked from tomorrow.// minTime and maxTime compare the time of day only, so they apply to every date.function MeetingField({ control }: { control: Control<FormValues> }) {  const adapter = useMuiXDateTimePickerAdapter<Dayjs, FormValues, 'meeting', HTMLDivElement>({    composeHelperText: true,    control,    maxDate: dayjs().add(3, 'month'),    maxTime: dayjs().hour(17).startOf('hour'),    messages: {      maxDate: 'Meetings can be booked up to three months ahead',      maxTime: 'Meetings must start by 17:00',      minDate: 'Meetings can be booked from tomorrow',      minTime: 'Meetings start at 09:00 or later',      minutesStep: 'Use a 15 minute slot (:00, :15, :30 or :45)',      required: 'Pick a meeting time',    },    // The date-time hooks type minDate and maxDate as required.    minDate: dayjs().add(1, 'day').startOf('day'),    minTime: dayjs().hour(9).startOf('hour'),    minutesStep: 15,    name: 'meeting',    required: true,    slotProps: {      textField: { helperText: 'From tomorrow, 09:00 to 17:00' },    },  });  return <DateTimePicker ampm={false} label="Meeting" {...adapter} />;}export default function Page() {  const { control, handleSubmit } = useForm<FormValues>({    defaultValues: { meeting: null },  });  return (    <LocalizationProvider dateAdapter={AdapterDayjs}>      <form        onSubmit={handleSubmit((values) => alert(values.meeting?.format('ddd D MMM, HH:mm')))}        noValidate      >        <Stack direction="column" spacing={2}>          <MeetingField control={control} />          <div>            <MuiButtonElement control={control} type="submit" variant="contained">              Book meeting            </MuiButtonElement>          </div>        </Stack>      </form>    </LocalizationProvider>  );}

Like the date-only hook, it must run inside a LocalizationProvider.

How it works

Value handling, the text field wiring (slotProps.textField, composeHelperText) and the "closing the picker counts as a blur" behavior are the same as in useMuiXDatePickerAdapter. What differs is validation.

Date checks, then time checks. The hook runs MUI X's validateDateTime. It first runs every date check from the DatePicker hook (minDate, maxDate, shouldDisableDate and so on, with the same keys and default messages). If those pass, it checks the time, in this order:

KeyFails whenDefault message
minTimeThe time is before minTimeTime is earlier than the minimum allowed time
maxTimeThe time is after maxTimeTime is later than the maximum allowed time
disableFutureThe value is after the current momentFuture date is not allowed
disablePastThe value is before the current momentPast date is not allowed
shouldDisableTime-hoursshouldDisableTime(value, "hours") returns trueHour is disabled
shouldDisableTime-minutesshouldDisableTime(value, "minutes") returns trueMinute is disabled
shouldDisableTime-secondsshouldDisableTime(value, "seconds") returns trueSecond is disabled
minutesStepThe minutes are not a multiple of minutesStepMinute step is not valid

Only the first failing check is reported. Override any message through messages, using the key from the table.

disablePast and disableFuture work to the minute. The date check compares by day, and the time check compares against the current time. So with disablePast, 08:00 today fails if it is already 10:00.

minTime and maxTime ignore the date by default. Only the time of day is compared, so minTime set to 09:00 means "09:00 or later on any day". Set disableIgnoringDatePartForTimeValidation: true to compare the full date and time instead. To express "not before this exact moment", pass the same value to minDate and minTime with that flag. The MobileDateTimePicker example below shows it.

The hook and the picker decide this flag differently. The hook uses the value you pass. MUI X's DateTimePicker ignores that prop and turns full date comparison on whenever disablePast, disableFuture, minDateTime or maxDateTime is set. If you combine a time-of-day minTime with disablePast, the picker lets users choose 07:00 tomorrow and the form then rejects it. Keep them aligned: use time-of-day limits without disablePast/disableFuture, or set the flag together with disablePast for an exact-moment limit.

The hook does not read minDateTime or maxDateTime. If you pass them straight to the picker, the picker greys out those times but the form still accepts a typed value outside the range. Use minTime/maxTime with the flag above so the rule is validated too.

The rules also drive the picker UI. The validation props are returned with the adapter props, so spreading them onto DateTimePicker also disables the matching days, hours and minutes in its views (subject to the flag difference above). The form-level check still matters for typed values and for values set with reset or setValue.

In TypeScript, minDate and maxDate are required props of the date-time hooks, unlike the date-only hooks. Pass real limits, as the example does. If they are missing at runtime, the hook falls back to the LocalizationProvider defaults (1900-01-01 and 2099-12-31).

Desktop, mobile and static versions

DateTimePicker picks its layout from the device: a popover when the pointer is precise, such as a mouse, and a dialog on touch screens. MUI X also has three versions with a fixed layout, and each has a hook, imported from @piplup/rhf-adapters/mui-x-date-pickers:

HookSpread ontoErrors shown by
useMuiXDesktopDateTimePickerAdapterDesktopDateTimePicker, a popover on every deviceslotProps.textField
useMuiXMobileDateTimePickerAdapterMobileDateTimePicker, a dialog on every deviceslotProps.textField
useMuiXStaticDateTimePickerAdapterStaticDateTimePicker, always visible, no text fieldyou render them

The desktop and mobile hooks call useMuiXDateTimePickerAdapter with the same props and return its result unchanged, so everything above applies to them. The static hook validates the same way, but returns the error for you to render.

DesktopDateTimePicker

useMuiXDesktopDateTimePickerAdapter returns props for DesktopDateTimePicker. Use the hook when you want a desktop date-time field with your own rules built in, for example one that always opens as a popover and blocks hours your team is not available.

This CallbackField only accepts hours between 08:00 and 20:00, skips the 13:00 lunch hour, and rejects past times. Open the picker to see the blocked hours, or type 13:15 and submit.

MM/DD/YYYY hh:mm

Times are in your local time zone

'use client';import Stack from '@mui/material/Stack';import { DesktopDateTimePicker, LocalizationProvider } from '@mui/x-date-pickers';import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';import { MuiButtonElement } from '@piplup/rhf-adapters/mui-material';import { useMuiXDesktopDateTimePickerAdapter } from '@piplup/rhf-adapters/mui-x-date-pickers';import dayjs from 'dayjs';import { useForm } from 'react-hook-form';import type { Dayjs } from 'dayjs';import type { Control } from 'react-hook-form';type FormValues = { callback: Dayjs | null };// Support calls happen between 08:00 and 20:00, never during the 13:00 lunch hour.function isClosedHour(hour: number) {  return hour < 8 || hour >= 20 || hour === 13;}function CallbackField({ control }: { control: Control<FormValues> }) {  const adapter = useMuiXDesktopDateTimePickerAdapter<    Dayjs,    FormValues,    'callback',    HTMLDivElement  >({    composeHelperText: true,    control,    disablePast: true,    maxDate: dayjs().add(14, 'day'),    messages: {      disablePast: 'Pick a time in the future',      maxDate: 'We can call you within the next two weeks',      required: 'When should we call you?',      'shouldDisableTime-hours': 'We call between 08:00 and 20:00, except 13:00 to 14:00',    },    minDate: dayjs(),    name: 'callback',    required: true,    shouldDisableTime: (value, view) => view === 'hours' && isClosedHour(value.hour()),    // A function is called with the picker's owner state; the adapter adds its own    // error, helperText and onBlur on top of what it returns.    slotProps: {      textField: () => ({ helperText: 'Times are in your local time zone' }),    },  });  return <DesktopDateTimePicker ampm={false} label="Call me back at" {...adapter} />;}export default function Page() {  const { control, handleSubmit } = useForm<FormValues>({    defaultValues: { callback: null },  });  return (    <LocalizationProvider dateAdapter={AdapterDayjs}>      <form        onSubmit={handleSubmit((values) => alert(values.callback?.format('ddd D MMM, HH:mm')))}        noValidate      >        <Stack direction="column" spacing={2}>          <CallbackField control={control} />          <div>            <MuiButtonElement control={control} type="submit" variant="contained">              Request callback            </MuiButtonElement>          </div>        </Stack>      </form>    </LocalizationProvider>  );}

shouldDisableTime runs once per time view. The hook calls shouldDisableTime(value, "hours"), then "minutes", then "seconds", and reports the first one that returns true under its own key: shouldDisableTime-hours, shouldDisableTime-minutes or shouldDisableTime-seconds. Check the view argument and only return true for the view your rule is about, as the example does. A rule that ignores view always fails on hours first, so only the hours message ever shows.

The same function greys out options in the popover's time columns, so users mostly hit the message when they type a time.

Errors and blur. error, helperText and onBlur go to the text field through slotProps.textField. You can pass slotProps.textField as a function of the picker's owner state, as the example does. The hook calls it and merges the result with its own props: an error message wins over your helperText, and both onBlur handlers run. Leaving the text field and closing the popover both mark the field as touched.

MobileDateTimePicker

useMuiXMobileDateTimePickerAdapter returns props for MobileDateTimePicker. Use the hook when you build a touch-first date-time field with rules that depend on the current moment, such as a pickup time that must be at least two hours away.

This PickupField rejects anything earlier than two hours from now and only accepts half-hour slots. Open the dialog to see the earlier times greyed out, or submit without a value to see the required message.

MM/DD/YYYY hh:mm

Tap to open the picker

'use client';import * as React from 'react';import Stack from '@mui/material/Stack';import { LocalizationProvider, MobileDateTimePicker } from '@mui/x-date-pickers';import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';import { MuiButtonElement } from '@piplup/rhf-adapters/mui-material';import { useMuiXMobileDateTimePickerAdapter } from '@piplup/rhf-adapters/mui-x-date-pickers';import dayjs from 'dayjs';import { useForm } from 'react-hook-form';import type { Dayjs } from 'dayjs';import type { Control } from 'react-hook-form';type FormValues = { pickup: Dayjs | null };// Orders need two hours to prepare. `disableIgnoringDatePartForTimeValidation`// makes the hook compare `minTime` against the full date and time, so it works as// a "not before this moment" rule instead of a daily opening time. `disablePast`// makes the picker do the same, so the views grey out the right times.function PickupField({ control }: { control: Control<FormValues> }) {  const [earliest] = React.useState(() => dayjs().add(2, 'hour').startOf('minute'));  const adapter = useMuiXMobileDateTimePickerAdapter<Dayjs, FormValues, 'pickup', HTMLDivElement>({    composeHelperText: true,    control,    disableIgnoringDatePartForTimeValidation: true,    disablePast: true,    maxDate: earliest.add(30, 'day'),    messages: {      maxDate: 'Orders can be placed up to 30 days ahead',      minDate: `Pickup can't be before ${earliest.format('ddd D MMM')}`,      minTime: `The earliest pickup is ${earliest.format('ddd HH:mm')}`,      minutesStep: 'Pickups are every half hour',      required: 'Choose a pickup time',    },    minDate: earliest,    minTime: earliest,    minutesStep: 30,    name: 'pickup',    required: true,    slotProps: {      textField: { helperText: 'Tap to open the picker' },    },  });  return <MobileDateTimePicker ampm={false} label="Pickup" {...adapter} />;}export default function Page() {  const { control, handleSubmit } = useForm<FormValues>({    defaultValues: { pickup: null },  });  return (    <LocalizationProvider dateAdapter={AdapterDayjs}>      <form        onSubmit={handleSubmit((values) => alert(values.pickup?.format('ddd D MMM, HH:mm')))}        noValidate      >        <Stack direction="column" spacing={2}>          <PickupField control={control} />          <div>            <MuiButtonElement control={control} type="submit" variant="contained">              Place order            </MuiButtonElement>          </div>        </Stack>      </form>    </LocalizationProvider>  );}

An earliest date and time. The hook does not read minDateTime. To validate "not before this moment", the example passes the same value to minDate and minTime and sets disableIgnoringDatePartForTimeValidation: true:

  • minDate rejects earlier days with the minDate message.
  • minTime with the flag compares the full date and time, so an earlier time on the same day fails with the minTime message. Without the flag, minTime would act as a daily opening time: a limit of 14:30 would also reject 09:00 tomorrow.
  • disablePast is set as well. MUI X's picker ignores the flag you pass and only compares full dates when disablePast, disableFuture, minDateTime or maxDateTime is set. With disablePast, the dialog greys out the same times the form rejects.

Create the limit once, for example with useState(() => dayjs().add(2, "hour")). A new dayjs() on every render moves the limit forward while the user fills the form, so a value that passed a moment ago can fail on submit.

Errors and blur. The text field gets error, helperText and onBlur through slotProps.textField. The hook also wraps onClose, so closing the dialog marks the field as touched, whether the user confirms or cancels. With mode: "onTouched", opening and cancelling the dialog on an empty required field shows the required message straight away.

StaticDateTimePicker

useMuiXStaticDateTimePickerAdapter returns props for StaticDateTimePicker. MuiXStaticDateTimePickerElement shows no validation message at all. Use the hook when the user needs to see why a value was rejected: you get the error state and message back and decide where to render them.

This PublishAtField schedules a post on the hour or half hour, up to two weeks ahead. Pick tomorrow, leave the time as it is, and submit to see the message rendered under the picker.

Select date & time
:
November 2026
SMTWTFS
'use client';import FormHelperText from '@mui/material/FormHelperText';import Stack from '@mui/material/Stack';import { LocalizationProvider, StaticDateTimePicker } from '@mui/x-date-pickers';import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';import { MuiButtonElement } from '@piplup/rhf-adapters/mui-material';import { useMuiXStaticDateTimePickerAdapter } from '@piplup/rhf-adapters/mui-x-date-pickers';import dayjs from 'dayjs';import { useForm } from 'react-hook-form';import type { Dayjs } from 'dayjs';import type { Control } from 'react-hook-form';type FormValues = { publishAt: Dayjs | null };// Posts go out on the hour or half hour, from now up to two weeks ahead.function PublishAtField({ control }: { control: Control<FormValues> }) {  const { error, helperText, required, ...adapter } = useMuiXStaticDateTimePickerAdapter<    Dayjs,    FormValues,    'publishAt',    HTMLDivElement  >({    composeHelperText: true,    control,    disablePast: true,    maxDate: dayjs().add(14, 'day'),    messages: {      disablePast: 'Choose a time later than now',      maxDate: 'You can schedule up to two weeks ahead',      required: 'Pick when to publish',      'shouldDisableTime-minutes': 'Posts go out at :00 or :30',    },    minDate: dayjs(),    name: 'publishAt',    required: true,    shouldDisableTime: (value, view) => view === 'minutes' && value.minute() % 30 !== 0,  });  return (    <div>      <StaticDateTimePicker ampm={false} slotProps={{ actionBar: { actions: [] } }} {...adapter} />      {error && <FormHelperText error>{helperText}</FormHelperText>}    </div>  );}export default function Page() {  const { control, handleSubmit } = useForm<FormValues>({    defaultValues: { publishAt: null },  });  return (    <LocalizationProvider dateAdapter={AdapterDayjs}>      <form        onSubmit={handleSubmit((values) =>          alert(`Scheduled for ${values.publishAt?.format('ddd D MMM, HH:mm')}`),        )}        noValidate      >        <Stack direction="column" spacing={2}>          <PublishAtField control={control} />          <div>            <MuiButtonElement control={control} type="submit" variant="contained">              Schedule post            </MuiButtonElement>          </div>        </Stack>      </form>    </LocalizationProvider>  );}

No slotProps.textField. Unlike the DateTimePicker hook, this one does not take slotProps and does not build a text field slot. It returns error, helperText and required as plain values. StaticDateTimePicker has no props for them, so take them off the result before spreading and render them yourself, as the example does with FormHelperText. With composeHelperText: true, helperText holds the error message.

No touched state. The hook ignores any onBlur you pass and has no onClose to wrap. The returned onBlur is React Hook Form's, but StaticDateTimePicker never calls it. The field is never marked as touched, so mode: "onBlur" and mode: "onTouched" do not validate it before the first submit. Use the default onSubmit mode or onChange.

Every pick changes the value. The form value updates on each selection in the picker, not when the user presses an action button. Picking a day with no value yet keeps the current time of day, so in the example it usually fails the :00/:30 rule until a minute is chosen. The example hides the action bar with slotProps={{ actionBar: { actions: [] } }} for that reason.

Ref. React Hook Form's ref and your ref are merged and attached to the picker's root element. There is no input to focus, so setFocus and shouldFocusError do nothing for this field.

Props and return value. The static hook takes no slotProps, inputRef or onClose:

Prop

Type

Prop

Type

Props

Prop

Type

Return value

Prop

Type

On this page