DatePicker
#
Overview#
FormattingThe 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 formatThe 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 stringsWhen 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: localesThe locale used by inputs is determined by the user's browser, you can manually
configure it with the <Localization>
Provider component.
#
Date and time inputDate 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#
APIautoFocus#
Pass focus to the DatePicker when it mounts.
calendarProps#
containerClassName#
Adds a css class to the input container element.
currentDate#
Default current date at which the calendar opens. If none is provided, opens at today's date or the value
date (if any).
defaultValue#
disabled#
dropUp#
Controls the opening direction of the DatePicker popup.
formats#
{}
includeTime#
Enable the time list component of the picker.
inputProps#
An object of props that is passed directly to the underlying input component.
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.
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.
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.
new Date(1900, 0, 1)
name#
The HTML name
attribute, passed directly to the input element.
onBlur#
The native onBlur
event, called when focus leaves the DatePicker entirely.
onChange#
A callback fired when the current value
changes.
onCurrentDateChange#
Change event Handler that is called when the currentDate is changed. The handler is called with the currentDate object.
onFocus#
The native onFocus
event, called when focus enters the DatePicker.
onKeyDown#
The native onKeyDown
event, called preventDefault
will prevent any custom behavior, included keyboard shortcuts.
onKeyPress#
The native onKeyPress
event, called preventDefault
will stop any custom behavior.
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.
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.
open#
Controls the visibility of the DatePicker popup. Use defaultOpen
to set an initial value for uncontrolled widgets.
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.
placeholder#
Text to display in the input when the value is empty.
popupComponent#
popupProps#
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.
readOnly#
Controls the read-only state of the DatePicker.
selectIcon#
Specify the element used to render the calendar dropdown icon.
calendar
step#
The amount of minutes between each entry in the time list.
timeInputProps#
timePrecision#
value#
Controls the current value of the DatePicker.
valueDisplayFormat#
A formatting options used to display the date value. For more information about formats visit the Localization page
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
valueFormat#
A formatting options used to display the date value. This is a shorthand for
setting both valueDisplayFormat
and valueEditFormat
.