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

useMuiXDatePickerAdapter

Returns adapter props for building custom MUI X DatePicker integrations with React Hook Form.

useMuiXDatePickerAdapter connects a field to React Hook Form and returns props you spread onto MUI X's DatePicker. It's what MuiXDatePickerElement uses internally.

Use the element for most forms. Reach for the hook when you want to build your own date field component, for example to bake in project-wide rules, wrap the picker in extra layout, or render a different picker variant with the same form wiring.

Import

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

Usage

This AppointmentField only accepts future weekdays and uses its own error messages. Submit the form empty, or pick a weekend date by typing it, to see the validation.

MM/DD/YYYY

Weekdays only

'use client';import Stack from '@mui/material/Stack';import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers';import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';import { MuiButtonElement } from '@piplup/rhf-adapters/mui-material';import { useMuiXDatePickerAdapter } from '@piplup/rhf-adapters/mui-x-date-pickers';import { useForm } from 'react-hook-form';import type { Dayjs } from 'dayjs';import type { Control } from 'react-hook-form';type FormValues = { appointment: Dayjs | null };// A reusable field with project-wide defaults baked in: weekdays only,// no past dates, and custom validation messages.function AppointmentField({ control }: { control: Control<FormValues> }) {  const adapter = useMuiXDatePickerAdapter<Dayjs, FormValues, 'appointment', HTMLDivElement>({    composeHelperText: true,    control,    disablePast: true,    messages: {      disablePast: "Appointments can't be in the past",      required: 'Pick a date for your appointment',      shouldDisableDate: "We're closed on weekends",    },    name: 'appointment',    required: true,    shouldDisableDate: (date) => date.day() === 0 || date.day() === 6,    slotProps: {      textField: { helperText: 'Weekdays only' },    },  });  return <DatePicker label="Appointment" {...adapter} />;}export default function Page() {  const { control, handleSubmit } = useForm<FormValues>({    defaultValues: { appointment: null },  });  return (    <LocalizationProvider dateAdapter={AdapterDayjs}>      <form        onSubmit={handleSubmit((values) => alert(values.appointment?.format('dddd, D MMMM YYYY')))}        noValidate      >        <Stack direction="column" spacing={2}>          <AppointmentField control={control} />          <div>            <MuiButtonElement control={control} type="submit" variant="contained">              Book            </MuiButtonElement>          </div>        </Stack>      </form>    </LocalizationProvider>  );}

The hook must run inside a LocalizationProvider, because it reads the date adapter to validate values and apply the default minDate/maxDate.

How it works

Value. The field value is passed to the picker as-is, with undefined converted to null so the picker stays controlled. Store date objects from your date library (e.g. Dayjs), not strings: the built-in validation runs on the stored value, and a string stored through transform makes it throw. Convert to a string when you submit instead.

Validation. The hook runs MUI X's own validateDate against minDate, maxDate, disablePast, disableFuture, shouldDisableDate, shouldDisableMonth and shouldDisableYear. Any failure becomes a React Hook Form error, so it blocks submission like any other rule. Empty values pass this check; add required to reject them.

Each failure has a default message, which you can replace through messages:

KeyDefault message
requiredPlease fill out this field.
invalidDateDate is not a valid date
disablePastPast date is not allowed
disableFutureFuture date is not allowed
minDateDate must be later than the minimum allowed date
maxDateDate should be earlier than the maximum allowed date
shouldDisableDateDate is not allowed
shouldDisableMonthMonth is not allowed
shouldDisableYearYear is not allowed

Errors and blur. The returned slotProps.textField sets error and helperText from the field state, and calls React Hook Form's onBlur so the field is marked as touched. Your own slotProps.textField (an object or a function) is merged in: an error message takes priority over your helperText, which shows when the field is valid. Closing the picker also counts as a blur.

Custom messages and rules.validate. Messages can be strings or functions. A function receives the value, and for minDate and maxDate also the limit, for example (value, minDate) => "Pick a date after " + minDate.format("LL"). A validate function or object in rules runs next to the built-in date validation, not instead of it.

Set composeHelperText: true to show the error message as the helper text, as the element does. Without it, only the error state is applied.

Desktop, mobile and static versions

DatePicker 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
useMuiXDesktopDatePickerAdapterDesktopDatePicker, a popover on every deviceslotProps.textField
useMuiXMobileDatePickerAdapterMobileDatePicker, a dialog on every deviceslotProps.textField
useMuiXStaticDatePickerAdapterStaticDatePicker, always visible, no text fieldyou render them

The desktop and mobile hooks call useMuiXDatePickerAdapter 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.

DesktopDatePicker

useMuiXDesktopDatePickerAdapter returns props for DesktopDatePicker. Use the hook when you build desktop date fields that work together, such as a check-in and check-out pair where one field's limits come from the other.

The check-out field reads the check-in value with useWatch and passes it as minDate and maxDate, so a stay must be 1 to 14 nights. Pick a check-in date, then type a check-out date before it and submit.

MM/DD/YYYY
MM/DD/YYYY
'use client';import Stack from '@mui/material/Stack';import { DesktopDatePicker, LocalizationProvider } from '@mui/x-date-pickers';import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';import { MuiButtonElement } from '@piplup/rhf-adapters/mui-material';import { useMuiXDesktopDatePickerAdapter } from '@piplup/rhf-adapters/mui-x-date-pickers';import { useForm, useWatch } from 'react-hook-form';import type { Dayjs } from 'dayjs';import type { Control } from 'react-hook-form';type FormValues = { checkIn: Dayjs | null; checkOut: Dayjs | null };function CheckInField({ control }: { control: Control<FormValues> }) {  const adapter = useMuiXDesktopDatePickerAdapter<Dayjs, FormValues, 'checkIn', HTMLDivElement>({    composeHelperText: true,    control,    disablePast: true,    messages: {      disablePast: "Check-in can't be in the past",      required: 'Choose a check-in date',    },    name: 'checkIn',    required: true,  });  return <DesktopDatePicker label="Check-in" {...adapter} />;}function CheckOutField({ control }: { control: Control<FormValues> }) {  const checkIn = useWatch({ control, name: 'checkIn' });  const adapter = useMuiXDesktopDatePickerAdapter<Dayjs, FormValues, 'checkOut', HTMLDivElement>({    composeHelperText: true,    control,    maxDate: checkIn?.add(14, 'day'),    messages: {      maxDate: 'Stays are limited to 14 nights',      minDate: 'Check-out must be after check-in',      required: 'Choose a check-out date',    },    // At least one night, at most 14. The limits follow the current check-in value    // because the rules are rebuilt on every render.    minDate: checkIn?.add(1, 'day'),    name: 'checkOut',    required: true,  });  return <DesktopDatePicker label="Check-out" {...adapter} />;}export default function Page() {  const { control, handleSubmit } = useForm<FormValues>({    defaultValues: { checkIn: null, checkOut: null },  });  return (    <LocalizationProvider dateAdapter={AdapterDayjs}>      <form        onSubmit={handleSubmit(({ checkIn, checkOut }) =>          alert(`${checkOut?.diff(checkIn, 'day')} nights`),        )}        noValidate      >        <Stack direction="column" spacing={2}>          <Stack direction={{ sm: 'row', xs: 'column' }} spacing={2}>            <CheckInField control={control} />            <CheckOutField control={control} />          </Stack>          <div>            <MuiButtonElement control={control} type="submit" variant="contained">              Check availability            </MuiButtonElement>          </div>        </Stack>      </form>    </LocalizationProvider>  );}

Limits from another field. The validation rule is rebuilt on every render from the current minDate and maxDate. When check-in changes, the check-out field re-renders with new limits, and the next validation of check-out uses them. If check-in is still empty, minDate and maxDate are undefined and the hook falls back to the LocalizationProvider defaults (1900-01-01 and 2099-12-31).

Changing check-in does not re-validate check-out on its own. A check-out error stays visible until check-out changes or the form is submitted. Call trigger("checkOut") in an effect after check-in changes if you need it immediately.

Errors and blur. The text field receives error, helperText and onBlur through slotProps.textField, and closing the popover also counts as a blur.

MobileDatePicker

useMuiXMobileDatePickerAdapter returns props for MobileDatePicker. Use the hook when you build a touch-first date field with your own rules, for example a booking field for a service that only runs in certain months.

This FerryDateField opens on the month view and only accepts April to October, up to the end of next year. Open the dialog to see the closed months greyed out, or submit empty to see the required message.

MM/DD/YYYY

Season: April to October

'use client';import Stack from '@mui/material/Stack';import { LocalizationProvider, MobileDatePicker } from '@mui/x-date-pickers';import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';import { MuiButtonElement } from '@piplup/rhf-adapters/mui-material';import { useMuiXMobileDatePickerAdapter } 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 = { crossing: Dayjs | null };// The ferry runs April to October (months 3 to 9 in dayjs), up to next year.function isOffSeason(date: Dayjs) {  return date.month() < 3 || date.month() > 9;}function FerryDateField({ control }: { control: Control<FormValues> }) {  const adapter = useMuiXMobileDatePickerAdapter<Dayjs, FormValues, 'crossing', HTMLDivElement>({    composeHelperText: true,    control,    disablePast: true,    maxDate: dayjs().add(1, 'year').endOf('year'),    messages: {      disablePast: 'That crossing has already sailed',      maxDate: 'Bookings open one season ahead',      required: 'Choose a crossing date',      shouldDisableMonth: 'The ferry only runs from April to October',    },    name: 'crossing',    required: true,    shouldDisableMonth: isOffSeason,    slotProps: {      textField: { helperText: 'Season: April to October' },    },  });  return (    <MobileDatePicker      label="Crossing date"      openTo="month"      views={['year', 'month', 'day']}      {...adapter}    />  );}export default function Page() {  const { control, handleSubmit } = useForm<FormValues>({    defaultValues: { crossing: null },  });  return (    <LocalizationProvider dateAdapter={AdapterDayjs}>      <form        onSubmit={handleSubmit((values) => alert(values.crossing?.format('dddd, D MMMM YYYY')))}        noValidate      >        <Stack direction="column" spacing={2}>          <FerryDateField control={control} />          <div>            <MuiButtonElement control={control} type="submit" variant="contained">              Book crossing            </MuiButtonElement>          </div>        </Stack>      </form>    </LocalizationProvider>  );}

Month and year rules. shouldDisableMonth and shouldDisableYear receive the full selected date during validation, and fail with their own keys (shouldDisableMonth, shouldDisableYear). The same functions grey out months and years in the dialog's month and year views. Checks run in a fixed order, shouldDisableDate, shouldDisableMonth, shouldDisableYear, then disablePast/disableFuture, minDate and maxDate, and only the first failure is reported. A past date in January shows the shouldDisableMonth message in the example, not the disablePast one.

Errors and blur. The text field gets error, helperText and onBlur through slotProps.textField. The hook also wraps onClose, so closing the dialog with either action button marks the field as touched. In onTouched mode, opening and cancelling the dialog on an empty required field shows the required message.

StaticDatePicker

useMuiXStaticDatePickerAdapter returns props for StaticDatePicker. MuiXStaticDatePickerElement validates but never shows a message. Use the hook when the picker is the main input on the page, such as a booking screen, and users need to see why their date was rejected.

This TourDateField blocks sold-out days and dates more than 60 days ahead. Submit without picking a day to see the message rendered under the picker.

November 2026
SMTWTFS
'use client';import FormHelperText from '@mui/material/FormHelperText';import Stack from '@mui/material/Stack';import { LocalizationProvider, StaticDatePicker } from '@mui/x-date-pickers';import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';import { MuiButtonElement } from '@piplup/rhf-adapters/mui-material';import { useMuiXStaticDatePickerAdapter } 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 = { tour: Dayjs | null };// Dates that are already sold out, e.g. loaded from an API.const soldOut = new Set([3, 4, 10].map((days) => dayjs().add(days, 'day').format('YYYY-MM-DD')));function TourDateField({ control }: { control: Control<FormValues> }) {  // StaticDatePicker has no text field: take the message out and render it below.  const { error, helperText, required, ...adapter } = useMuiXStaticDatePickerAdapter<    Dayjs,    FormValues,    'tour',    HTMLDivElement  >({    composeHelperText: true,    control,    disablePast: true,    maxDate: dayjs().add(60, 'day'),    messages: {      maxDate: 'Tours open 60 days in advance',      required: 'Pick a tour date',      shouldDisableDate: 'This tour is sold out',    },    name: 'tour',    required: true,    shouldDisableDate: (date) => soldOut.has(date.format('YYYY-MM-DD')),  });  return (    <div>      <StaticDatePicker        displayStaticWrapperAs="desktop"        slotProps={{ actionBar: { actions: [] } }}        {...adapter}      />      {error && <FormHelperText error>{helperText}</FormHelperText>}    </div>  );}export default function Page() {  const { control, handleSubmit } = useForm<FormValues>({    defaultValues: { tour: null },  });  return (    <LocalizationProvider dateAdapter={AdapterDayjs}>      <form        onSubmit={handleSubmit((values) => alert(values.tour?.format('dddd, D MMMM YYYY')))}        noValidate      >        <Stack direction="column" spacing={2}>          <TourDateField control={control} />          <div>            <MuiButtonElement control={control} type="submit" variant="contained">              Reserve            </MuiButtonElement>          </div>        </Stack>      </form>    </LocalizationProvider>  );}

Error display is up to you. The hook does not build slotProps.textField. It returns error, helperText and required as plain values, and StaticDatePicker has no props for them. Take them off the result before spreading, then render them, as the example does with FormHelperText. Set composeHelperText: true so that helperText holds the error message.

No hint text. The hook does not accept a helperText prop (it is cleared even if passed), so helperText in the result is either the error message or undefined. Write any hint text directly in your component.

No touched state. Any onBlur you pass is ignored. The returned onBlur is React Hook Form's, but StaticDatePicker never calls it, so the field is never marked as touched. In onBlur or onTouched mode it is only validated after the first submit.

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 have no effect on this field.

The validation props are also spread onto the picker, so sold-out days and dates past maxDate are greyed out in the calendar. The form-level check still catches values set through defaultValues, reset or setValue.

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