React MUI MobileDateTimePicker API
Last Updated :
28 Apr, 2025
React MUI is a UI library that provides fully-loaded components, bringing our own design system to our production-ready components. MUI is a user interface library that provides predefined and customizable React components for faster and easy web development, these Material-UI components are based on top of Material Design by Google.
The MobileDateTimePicker API is part of the Material-UI library for React. It provides a way to select a date and time on mobile devices with an intuitive and user-friendly interface. The API offers various options for customization and integration with other Material-UI components.
Props List:
- onChange: This is a callback function that is fired when the selected date changes.
- renderInput: This prop allows us to customize the rendered input. This is a function.
- acceptRegex: This is the regular expression that is used to detect "accepted" symbols.
- className: This is the class name that is applied to the root component. The type of this prop is a string.
- closeOnSelect: This is a boolean prop. If this is set to true, the popup or dialog will immediately close after submitting the full date.
- components: These are the overridable components. The type of this prop is an object. The default value is an empty object i.e. {}.
- componentsProps: These are the props used for each component slot. The type of this prop is an object. The default value is an empty object i.e. {}.
- dayOfWeekFormatter: This is a function that formats the day of the week displayed in the calendar header. The default value of this function is (day) => day.charAt(0).toUpperCase().
- defaultCalendarMonth: This is used to display the default calendar month when the value is equal to null.
- DialogProps: These are the props that are applied to the dialog component. The type of this prop is any.
- disabled: This is a boolean prop. If the value of this prop is set to true, the picker and text field are disabled. The default value of this prop is false.
- disableFuture: This is a boolean prop. If this is set to true, the future days are disabled. The default value of this prop is false.
- disableHighlightToday: This is a boolean prop. If this is set to true, today's date is rendered without being highlighted with a circle. The default value of this prop is false.
- disableMaskedInput: This is a boolean prop. If this is set to true, this disables the mask on the keyboard. This has to be used rarely. And you have to pass the proper mask for your format. The default value of this prop is false.
- disableOpenPicker: This is a boolean prop. If this is set to true, it does not render the open picker button. The default value of this prop is false.
- disablePast: This is a boolean prop. If this is set to true, the past days are disabled. The default value of this prop is false.
- displayWeekNumber: This is a boolean prop. If this is set to true, the week number will be displayed in the calendar. The default value is false.
- fixedWeekNumber: The calendars will show more weeks in order to match this value. The type of this prop is a number and the default value is undefined.
- format: This is the format of the date when rendered in the input. The type of this prop is String.
- inputRef: Passes a ref to the input element. The type of this prop is a function.
- label: This is label content. The type of this prop is a node.
- localeText: This is the locale for component texts. This allows overriding texts coming from LocalizationProvider and theme. The type of this prop is an object.
- loading: This is a boolean prop. If this is set to true, it renders LoadingComponent in the calendar view instead of the list view. It can be used to preload information and display that information in a calendar. The default value of this prop is false.
- maxDate: This is the maximally selectable date. You cannot select a date that is greater than the maxDate.
- minDate: This is the minimally selectable date. You cannot select a date that is lesser than the minDate.
- onAccept: This is a callback function that gets fired when the date gets accepted.
- onClose: This is a callback function that gets fired when the popup requests to be closed. It should be used in a controlled mode.
- onError: This is a callback function that gets fired when the input value or new value prop validation returns a new validation error.
- onMonthChange: This is a callback function that gets fired when the month change is detected.
- onOpen: This is a callback function that gets fired when the popup requests to be opened. It should be used in a controlled mode.
- onViewChange: This is a callback function that gets fired when a view change is detected.
- onYearChange: This is a callback function that gets fired when a year change is detected.
- shouldDisableDate: This is a function that is used to disable a specific date.
- shouldDisableMonth: This is a function that is used to disable a specific month.
- shouldDisableYear: This is a function that is used to disable a specific year.
- showDaysOutsideCurrentMonth: This is a boolean prop. If it is set to true, days that have outsideCurrentMonth={true} get displayed. The default value is false.
- ampm: This is a boolean prop.12h/24h view for hour selection clock. The default value is 12h clock.
- ampmInClock: This is a boolean prop. This is used to display ampm controls under the clock. The default value is false.
- maxDateTime: It is the maximal selectable moment of time binding to the date, to set max time each day use maxTime.
- maxTime: It is the maximum acceptable time.
- minDateTime: It is the minimum selectable moment of time binding to the date, to set min time in each day use minTime.
- minTime: It is the minimum acceptable time.
- minutesStep: Step over minutes.
- shouldDisableTime: This is a function that dynamically checks if time is disabled or not. If it returns a false appropriate time point will not be acceptable.
- timeIcon: Time tab icon.
- autoFocus: This is a boolean prop. If this is set to true, the main element is focused during the first month. The default value of this prop is false.
- monthsPerRow: These are the months rendered per row. The default value of this prop is 3.
- open: This is a boolean prop. This controls the popup or dialog open state. The default value is false.
- openTo: This is the default visible view. It is used when the component view is not controlled.
- orientation: This prop forces rendering in a particular direction. The type of this prop is landscape or portrait.
- reduceAnimations: This is a boolean prop that disables heavy animations.
- renderLoading : This is a function that displays the component when passed loading as true.
- selectedSections : This displays the currently selected versions.
- slotProps: These are the props that are used for each component slot. The type of this prop is an object. The default value is an empty object i.e. {}.
- slots: These are the overridable component slots. The type of this prop is an object. The default value is an empty object i.e. {}.
- sx: This is the system prop that allows defining system overrides as well as additional CSS styles. This is the array of functions or objects.
- view: This is the visible view. It is used when the component view is controlled.
- viewRenderers: This defines custom view renderers for each section.
- views: These are the available views.
- yearsPerRow: These are the years rendered per row. The default value of this prop is 3.
Slots List: Here is a list of the available slots in the MobileDateTimePicker component:
- ActionBar: The action bar, which is placed below picker views. The default value is PickersActionBar.
- LeftArrowButton: This is a button that allows you to switch to the left view. The default value is IconButton.
- LeftArrowIcon: This is an icon that appears in the view switch button on the left side. The default value is ArrowLeft.
- OpenPickerIcon: This is an icon that is displayed in the open picker button. The default value is calendar or clock.
- RightArrowButton: This is a button that allows you to switch to the right view.The default value is IconButton.
- RightArrowIcon: This is an icon that is displayed on the right view switch button. The default value is ArrowRight.
- SwitchViewButton: This is a button that is displayed to switch between different calendar views. The default value is IconButton.
- SwitchViewIcon: This is the icon that appears in the SwitchViewButton. The default value is ArrowDropDown.
- Tabs: The tabs enable toggling between date and time pickers. The default value is DateTimePickerTabs.
Syntax: The syntax of MobileDateTimePicker is as follows:
<MobileDateTimePicker
label="For mobile"
value={value}
onChange={(newValue) => {
setValue(newValue);
}}
renderInput={(params) => <TextField {...params} />}
/>
Installing React App:
Step 1: Create a React app using the following command.
npx create-react-app mobile-date-time-picker example
Step 2: Now get into the project directory.
cd mobile-date-picker-time-example
Installing Material-UI: Installing Material-UI's source files via npm/yarn, and they take care of injecting CSS needed.
npm install @material-ui/core
Or
yarn add @material-ui/core
Installing the required package:
npm install @mui/material @emotion/react @emotion/styled
npm install @mui/x-date-pickers dayjs
Project Structure:
Project Structure
Importing MobileDateTimePicker:
import { MobileDateTimePicker } from '@mui/x-date-pickers-pro/MobileDateTimePicker';
OR
import { MobileDateTimePicker } from '@mui/x-date-pickers/MobileDateTimePicker';
OR
import { MobileDateTimePicker } from '@mui/x-date-pickers-pro';
OR
import { MobileDateTimePicker } from '@mui/x-date-pickers';
Step to run the application:
npm start
Example 1:
JavaScript
import * as React from 'react';
import dayjs from 'dayjs';
import TextField from '@mui/material/TextField';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from
'@mui/x-date-pickers/LocalizationProvider';
import { DateTimePicker } from
'@mui/x-date-pickers/DateTimePicker';
import { MobileDateTimePicker } from
'@mui/x-date-pickers/MobileDateTimePicker';
import { DesktopDateTimePicker } from
'@mui/x-date-pickers/DesktopDateTimePicker';
import Stack from '@mui/material/Stack';
export default function ResponsiveDateTimePickers() {
const [value, setValue] = React
.useState(dayjs('2023-03-02T00:00:00.000Z'));
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<h1 style={{ color: 'green' }}>GeeksForGeeks</h1>
<h3>React MUI MobileDateTimePicker API</h3>
<Stack spacing={3}>
<MobileDateTimePicker
label="For mobile"
value={value}
onChange={(newValue) => {
setValue(newValue);
}}
renderInput={(params) => <TextField {...params} />}
/>
</Stack>
</LocalizationProvider>
);
}
Output:
Selecting the date and time
Example 2: We will see the ways to restrict date and time selection. There are two ways to do this:
- By using minDateTime or maxDateTime, it is possible to restrict the time selection to before or after a particular moment of time.
- By using minTime or maxTime, you can disable selecting times before or after a certain time each day respectively.
JavaScript
import * as React from 'react';
import dayjs from 'dayjs';
import TextField from '@mui/material/TextField';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from
'@mui/x-date-pickers/LocalizationProvider';
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
import Stack from '@mui/material/Stack';
export default function DateTimeValidation() {
const [value, setValue] = React.useState(dayjs('2023-03-02'));
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<h1 style={{ color: 'green' }}>GeeksForGeeks</h1>
<h3>React MUI MobileDateTimePicker API</h3>
<Stack spacing={3}>
<DateTimePicker
renderInput={(params) => <TextField {...params} />}
label="Ignore date and time"
value={value}
onChange={(newValue) => {
setValue(newValue);
}}
minDateTime={dayjs('2023-03-02T12:00')}
/>
<DateTimePicker
renderInput={(params) => <TextField {...params} />}
label="Ignore time in each day"
value={value}
onChange={(newValue) => {
setValue(newValue);
}}
minDate={dayjs('2023-02-02')}
minTime={dayjs('2022-02-03T08:00')}
maxTime={dayjs('2022-02-03T18:45')}
/>
</Stack>
</LocalizationProvider>
);
}
Output:
Reference: https://mui.com/x/api/date-pickers/mobile-date-time-picker/
Similar Reads
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
React Fundamentals
React IntroductionReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability. Why Use React?Before React, web development faced issues like slow DOM updates and mes
7 min read
React Environment SetupTo run any React application, we need to first setup a ReactJS Development Environment. In this article, we will show you a step-by-step guide to installing and configuring a working React development environment.Pre-requisite:We must have Nodejs installed on our PC. So, the very first step will be
3 min read
React JS ReactDOMReactDOM is a core React package that provides methods to interact with the Document Object Model, or DOM. This package allows developers to access and modify the DOM. It is a package in React that provides DOM-specific methods that can be used at the top level of a web app to enable an efficient wa
3 min read
React JSXJSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, itâs actually a syntax extensi
5 min read
ReactJS Rendering ElementsIn this article we will learn about rendering elements in ReactJS, updating the rendered elements and will also discuss about how efficiently the elements are rendered.What are React Elements?React elements are the smallest building blocks of a React application. They are different from DOM elements
3 min read
React ListsReact Lists are used to display a collection of similar data items like an array of objects and menu items. It allows us to dynamically render the array elements and display repetitive data.Rendering List in ReactTo render a list in React, we will use the JavaScript array map() function. We will ite
5 min read
React FormsForms are an essential part of any application used for collecting user data, processing payments, or handling authentication. React Forms are the components used to collect and manage the user inputs. These components include the input elements like text field, check box, date input, dropdowns etc.
5 min read
ReactJS KeysA key serves as a unique identifier in React, helping to track which items in a list have changed, been updated, or removed. It is particularly useful when dynamically creating components or when users modify the list. In this article, we'll explore ReactJS keys, understand their importance, how the
5 min read
Components in React
React ComponentsIn React, React components are independent, reusable building blocks in a React application that define what gets displayed on the UI. They accept inputs called props and return React elements describing the UI.In this article, we will explore the basics of React components, props, state, and render
4 min read
ReactJS Functional ComponentsIn ReactJS, functional components are a core part of building user interfaces. They are simple, lightweight, and powerful tools for rendering UI and handling logic. Functional components can accept props as input and return JSX that describes what the component should render.Stateless (before hooks)
5 min read
React Class ComponentsClass components are ES6 classes that extend React.Component. They allow state management and lifecycle methods for complex UI logic.Used for stateful components before Hooks.Support lifecycle methods for mounting, updating, and unmounting.The render() method in React class components returns JSX el
4 min read
ReactJS Pure ComponentsReactJS Pure Components are similar to regular class components but with a key optimization. They skip re-renders when the props and state remain the same. While class components are still supported in React, it's generally recommended to use functional components with hooks in new code for better p
4 min read
ReactJS Container and Presentational Pattern in ComponentsIn this article we will categorise the react components in two types depending on the pattern in which they are written in application and will learn briefly about these two categories. We will also discuss about alternatives to this pattern. Presentational and Container ComponentsThe type of compon
2 min read
ReactJS PropTypesIn ReactJS PropTypes are the property that is mainly shared between the parent components to the child components. It is used to solve the type validation problem. Since in the latest version of the React 19, PropeTypes has been removed. What is ReactJS PropTypes?PropTypes is a tool in React that he
5 min read
React Lifecycle In React, the lifecycle refers to the various stages a component goes through. These stages allow developers to run specific code at key moments, such as when the component is created, updated, or removed. By understanding the React lifecycle, you can better manage resources, side effects, and perfo
7 min read
React Hooks
Routing in React
Advanced React Concepts
React Projects