MuiXTimePickerElement
Use the MUI X TimePicker with react-hook-form. MuiXTimePickerElement binds the picked time and its validation to a form field, no Controller needed.
Import
import { MuiXTimePickerElement } from '@piplup/rhf-adapters/mui-x-date-pickers';Usage
'use client';import Stack from '@mui/material/Stack';import { LocalizationProvider } from '@mui/x-date-pickers';import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';import { MuiButtonElement } from '@piplup/rhf-adapters/mui-material';import { MuiXTimePickerElement } from '@piplup/rhf-adapters/mui-x-date-pickers';import dayjs from 'dayjs';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { reminderTime: dayjs() }, }); return ( <LocalizationProvider dateAdapter={AdapterDayjs}> <form onSubmit={handleSubmit((values) => alert(JSON.stringify(values, null, 2)))}> <Stack direction="column" spacing={2}> <MuiXTimePickerElement control={control} label="Reminder time" name="reminderTime" /> <div> <MuiButtonElement control={control} type="submit" variant="contained"> Submit </MuiButtonElement> </div> </Stack> </form> </LocalizationProvider> );}Desktop, mobile and static versions
MuiXTimePickerElement renders MUI X's TimePicker, which picks its layout from the device: a popover when the pointer is precise, such as a mouse, and a dialog on touch screens. To fix the layout, use one of these elements instead. They come from the same import path and take the same props, validation and messages as MuiXTimePickerElement.
| Element | Renders | Opens as |
|---|---|---|
MuiXDesktopTimePickerElement | DesktopTimePicker | A popover next to the field, on every device |
MuiXMobileTimePickerElement | MobileTimePicker | A dialog with action buttons, on every device |
MuiXStaticTimePickerElement | StaticTimePicker | Always visible on the page, with no text field |
'use client';import Stack from '@mui/material/Stack';import { LocalizationProvider } from '@mui/x-date-pickers';import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';import { MuiButtonElement } from '@piplup/rhf-adapters/mui-material';import { MuiXDesktopTimePickerElement } from '@piplup/rhf-adapters/mui-x-date-pickers';import dayjs from 'dayjs';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { reminderTime: dayjs() }, }); return ( <LocalizationProvider dateAdapter={AdapterDayjs}> <form onSubmit={handleSubmit((values) => alert(JSON.stringify(values, null, 2)))}> <Stack direction="column" spacing={2}> <MuiXDesktopTimePickerElement control={control} label="Reminder time" name="reminderTime" /> <div> <MuiButtonElement control={control} type="submit" variant="contained"> Submit </MuiButtonElement> </div> </Stack> </form> </LocalizationProvider> );}MuiXStaticTimePickerElement validates the field but shows no error message, because a static picker has no text field to put it in. It takes no slotProps, inputRef or onClose, and focus can't move to it when validation fails. To show the message, build the field with useMuiXStaticTimePickerAdapter and render the error yourself.
Each version has its own hook for custom fields, documented on the useMuiXTimePickerAdapter page.
Props
Prop
Type
MuiXTimePickerElement supports all standard props of the MUI X TimePicker component, along with additional adapter-specific props. For a complete list of available TimePicker properties, refer to the MUI X Date Pickers API documentation.
The
refis forwarded to the underlying<TimePicker />component.
Notes
- For custom time pickers, build on
useMuiXTimePickerAdapter.
See also
MuiXTimeFieldElement
Use the MUI X TimeField with react-hook-form. MuiXTimeFieldElement binds the typed time and its validation to a form field, no Controller needed.
MuiXYearCalendarElement
Use the MUI X YearCalendar with react-hook-form. MuiXYearCalendarElement binds the selected year and its validation to a form field, no Controller needed.