Skip to main content

DatePicker

Overview#

Formatting#

The format of dates can be adjusted per component. The exact type of a format is dependent on the configured localizer. It may be a string, as is the case for Luxon or DateFns, an options object passed to Intl directly. The default case uses the built-in Intl APIs.

Editing format#

The best date format to read is not always the easier to input. You can provide differentiate between edit and display formats; the former is used while the input is focused.

Parsing date strings#

When a user types a value into the textbox it need's to parsed into a proper Date object. The built-in parsing logic simply passes the value to new Date. This often works fine, but can produce confusing results given how varied of an input the Date constructor will accept. Localizer's may provide more structured parsing, if the backing library supports it. The parse prop provides another escape hatch for per component parse tweaking.

I18n: locales#

The locale used by inputs is determined by the user's browser, you can manually configure it with the <Localization> Provider component.

Date and time input#

Date and time input is hard, and rarely does a single input meet all use cases well. To meet the variety of user needs, inputs can be combined and configured to support the input pattern that works best for your users.

Keyboard Shortcuts#

alt + down arrow
open calendar or time
alt + up arrow
close calendar or time
down arrow
move focus to next item
up arrow
move focus to previous item
home
move focus to first item
end
move focus to last item
enter
select focused item
any key
search list for item starting with key

API#

autoFocus#

Pass focus to the DatePicker when it mounts.

type: boolean

calendarProps#

type: Partial<CalendarProps>

containerClassName#

Adds a css class to the input container element.

type: string

currentDate#

Default current date at which the calendar opens. If none is provided, opens at today's date or the value date (if any).

type: Date

defaultValue#

type: Datenull

disabled#

type: boolean

dropUp#

Controls the opening direction of the DatePicker popup.

type: boolean

formats#

type: DateFormats<InferFormat<TLocalizer>>
default:{}

includeTime#

Enable the time list component of the picker.

type: boolean

inputProps#

An object of props that is passed directly to the underlying input component.

type: Partial<DatePickerInputProps>

max#

The maximum Date that can be selected. Max only limits selection, it doesn't constrain the date values that can be typed or pasted into the widget. If you need this behavior you can constrain values via the onChange handler.

type: Date
default:new Date(2099, 11, 31)

messages#

Object hash containing display text and/or text for screen readers. Use the messages object to localize widget text or provide custom rendering.

type: intersection<CalendarProps['messages'], { dateButton?: string }>

min#

The minimum Date that can be selected. Min only limits selection, it doesn't constrain the date values that can be typed or pasted into the widget. If you need this behavior you can constrain values via the onChange handler.

type: Date
default:new Date(1900, 0, 1)

name#

The HTML name attribute, passed directly to the input element.

type: string

onBlur#

The native onBlur event, called when focus leaves the DatePicker entirely.

type: () => void

onChange#

A callback fired when the current value changes.

type: (date: Datenullundefined, rawValue: string) => void

onCurrentDateChange#

Change event Handler that is called when the currentDate is changed. The handler is called with the currentDate object.

type: () => void

onFocus#

The native onFocus event, called when focus enters the DatePicker.

type: () => void

onKeyDown#

The native onKeyDown event, called preventDefault will prevent any custom behavior, included keyboard shortcuts.

type: (e: ReactKeyboardEvent<HTMLDivElement>) => void

onKeyPress#

The native onKeyPress event, called preventDefault will stop any custom behavior.

type: (e: ReactKeyboardEvent<HTMLDivElement>) => void

onSelect#

This handler fires when an item has been selected from the list. It fires before the onChange handler and fires regardless of whether the value has actually changed.

type: (date: Datenull, rawValue: string) => void

onToggle#

A callback fired with the DatePicker's popup visibility is about to change.

Use in conjunction with the open prop to manually control the popup visibility.

type: (isOpen: boolean) => void

open#

Controls the visibility of the DatePicker popup. Use defaultOpen to set an initial value for uncontrolled widgets.

type: boolean

parse#

Determines how the widget parses the typed date string into a Date object. You can provide an array of formats to try, or provide a function that returns a date to handle parsing yourself. When parse is unspecified and the format prop is a string parse will automatically use that format as its default.

type: stringunknown

placeholder#

Text to display in the input when the value is empty.

type: string

popupComponent#

type: ReactComponentType<PopupProps>

popupProps#

type: object

popupTransition#

A Transition component from react-transition-group. The provided component will be used instead of the default SlideDownTransition for fully customizable animations. The transition component is also injected with a dropUp prop indicating the direction it should open.

type: ReactComponentType<TransitionProps>

readOnly#

Controls the read-only state of the DatePicker.

type: boolean

selectIcon#

Specify the element used to render the calendar dropdown icon.

type: ReactReactNode
default:calendar

step#

The amount of minutes between each entry in the time list.

type: number

timeInputProps#

type: Partial<TimeInputProps>

timePrecision#

type: 'minutes''seconds''milliseconds'

value#

Controls the current value of the DatePicker.

type: Datenull

valueDisplayFormat#

A formatting options used to display the date value. For more information about formats visit the Localization page

type: InferFormat<TLocalizer>

valueEditFormat#

A formatting options used while the date input has focus. Useful for showing a simpler format for inputing. For more information about formats visit the Localization page

type: InferFormat<TLocalizer>

valueFormat#

A formatting options used to display the date value. This is a shorthand for setting both valueDisplayFormat and valueEditFormat.

type: InferFormat<TLocalizer>