DatePicker Component
The DatePicker component provides an input with an integrated calendar popup for selecting a single date. It supports date formatting, parsing, min/max date constraints, strict mode validation, custom calendar templates, and can be rendered as an inline picker or a dialog-based picker.
Usage
To import and use the DatePicker component in your application, use the following code snippet:
Demos
Explore the demos of the React DatePicker component. Refer to this page.
Props
The following table outlines the props for the DatePicker component:
| Name | Type | Default | Description |
|---|---|---|---|
| cellTemplate | ((props: CalendarCellProps) => node) | - | Specifies a custom template for rendering the content of each calendar cell. Can be a React node or a function that returns a React node. |
| clearButton | boolean | true | Specifies whether to show the clear button within the input field. |
| defaultValue | Date | - | Specifies the default selected date of the DatePicker for uncontrolled mode. |
| depth | CalendarView.Month | Sets the most granular view the user can navigate down to.
For example, a | |
| disableFutureDays | boolean | false | When |
| disableOtherMonthNavigation | boolean | false | Prevents navigation when clicking on dates from other months in month view |
| disablePastDays | boolean | false | When |
| disabled | boolean | false | Specifies whether the component is disabled or not. |
| editable | boolean | true | Specifies whether the input field can be edited directly. When false, only allows selection via calendar. |
| firstDayOfWeek | number | 0 | Specifies the first day of the week: |
| footerTemplate | ((props: CalendarFooterProps) => node) | - | Specifies a custom template for the calendar footer. If not provided, a default footer with a 'Today' button is rendered. |
| format | string | 'M/d/yyyy' | Specifies the date format string for displaying and parsing date values. Examples: 'MM/dd/yyyy', 'yyyy-MM-dd', etc. |
| headerTemplate | ((props: CalendarHeaderProps) => node) | - | Specifies a custom template for the calendar header. If not provided, a default header with navigation controls is rendered. |
| inputFormats | string[] | - | Specifies an array of acceptable date input formats for parsing user input. Can be an array of strings or FormatObject. |
| labelMode | 'Never' | Specifies the float label behavior. Possible values:
| |
| maxDate | Date | new Date(2099, 11, 31) | Specifies the maximum date that can be selected in the Calendar. |
| minDate | Date | new Date(1900, 0, 1) | Specifies the minimum date that can be selected in the Calendar. |
| open | boolean | false | Specifies whether the calendar popup is open or closed. |
| openOnFocus | boolean | false | When true, should open the calendar popup on input focus. |
| orientation | Orientation.Vertical | Specifies the layout orientation of the calendar. | |
| pickerIcon | node | undefined | Specifies the calendar/datepicker icon rendered in the input. |
| pickerVariant | PickerVariant.Auto | Specifies the display variant of the calendar popup.
| |
| placeholder | string | - | Specifies the placeholder text to display in the input box when no value is set. |
| readOnly | boolean | false | Specifies whether the component is in read-only mode. When enabled, users cannot change input value or open the picker. |
| required | boolean | false | Specifies whether the DatePicker is a required field in a form. When set to true, the component will be marked as required. |
| showDaysOutsideCurrentMonth | boolean | true | When |
| showTodayButton | boolean | true | Specifies whether the calendar shows the Today button in the footer. |
| showToolBar | boolean | false | Specifies whether the calendar displays an additional toolbar for showing the full selected date. |
| size | Size | Size.Medium | Specifies the size style of the Timepicker. Options include 'Small', 'Medium' and 'Large'. |
| start | CalendarView.Month | Specifies the initial view that the calendar renders. | |
| strictMode | boolean | false | Enables strict date validation mode. When enabled, invalid values are prevented or auto-corrected. |
| valid | boolean | false | Overrides the validity state of the component. If valid is set, the required property will be ignored. |
| validationMessage | string | - | Controls the form error message of the component. |
| validityStyles | boolean | true | If set to false, no visual representation of the invalid state of the component will be applied. |
| value | Date | null | - | Specifies the selected date of the DatePicker for controlled usage. |
| variant | Variant.Standard | Specifies the visual style variant of the component. | |
| weekDaysFormat | WeekDaysFormats.Short | Specifies the format of the day names to be displayed in the week header. | |
| weekNumber | boolean | false | When |
| weekRule | WeekRule.FirstDay | Specifies the rule for defining the first week of the year. | |
| zIndex | number | 1000 | Sets the z-index value for the dropdown popup, controlling its stacking order relative to other elements on the page. |
Events
The following table outlines the events for the DatePicker component:
| Name | Type | Description |
|---|---|---|
| onChange | (event: DatePickerChangeEvent) => void | Triggers when the DatePicker value is changed. |
| onClose | ( ) => void | Triggers when the calendar popup closes. |
| onOpen | ( ) => void | Triggers when the calendar popup opens. |
| onViewChange | (event: ViewChangeEvent) => void | Triggers when the calendar navigates to a new view or date range. |