Skip to content

Date Picker

The Date Picker let the user select a date.

Date pickers are displayed with:

  • Dialogs on mobile
  • Text field dropdowns on desktop

Basic usage

The Date Picker is rendered as a modal dialog on mobile, and a textbox with a popup on desktop.

Press Enter to start editing

Component composition

The Date Picker components are built using the DateField for the keyboard editing and the DateCalendar for the view editing. All the documented props of those two components can also be passed to the Date Picker components.

Check-out their documentation page for more information:

Uncontrolled vs. Controlled

The component can be uncontrolled or controlled

Press Enter to start editing

Responsiveness

The Date Picker component is designed and optimized for the device it runs on.

  • The MobileNextDatePicker component works best for touch devices and small screens.
  • The DesktopNextDatePicker component works best for mouse devices and large screens.

By default, the NextDatePicker component renders the desktop version if the media query @media (pointer: fine) matches. This can be customized with the desktopModeMediaQuery prop.

There are certain caveats when testing pickers, please refer to this section for more information.

Press Enter to start editing

Static mode

It is also possible to render the Date Picker without the modal/popover and text field. This can be helpful when building custom popover/modal containers.

SMTWTFS
Press Enter to start editing

Form props

The Date Picker component can be disabled or read-only.

Press Enter to start editing

Views

The component can contain three views: day, month, and year. By default, only the day and year views are enabled.

You can customize the enabled views using the views prop. Views will appear in the order they're included in the views array.

Press Enter to start editing

Landscape orientation

By default, the Date Picker automatically sets the orientation based on the window.orientation value.

You can force a specific orientation using the orientation prop.

Select date

Thu, Apr 7

SMTWTFS
Press Enter to start editing

Helper text

You can show a helper text with the date format accepted.

MM / DD / YYYY

Press Enter to start editing

Custom input component

You can customize the rendering of the input with the Input component slot. Make sure to spread inputProps correctly to the custom input component.

Press Enter to start editing

Validation

You can find the documentation in the Validation page.

Localization

You can find the documentation about localization in the Date localization and Component localization.

API

See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.