DatePicker

@ui5/webcomponents
<ui5-date-picker>

Basic DatePicker

<ui5-date-picker id="myDatepicker1"></ui5-date-picker>
	

DatePicker with Placeholder, Tooltip, Events, ValueState and valueStateMessage

The value is not valid. Please provide valid value
<ui5-date-picker id='myDatepicker2' placeholder='Delivery Date...' title='Delivery Date!'>
	<div slot="valueStateMessage">The value is not valid. Please provide valid value</div>
</ui5-date-picker>
<script>
	const dp = document.getElementById('myDatepicker2');
	dp.addEventListener('change', (e) => {
		dp.setAttribute('value-state', e.detail.valid ? 'None' : 'Error');
		console.log('change: ', e.detail);
	});
	dp.addEventListener('input', (e) => console.log('input: ', e.detail));
</script>
	

DatePicker with Minimum and Maximum Date - 1/1/2020 - 4/5/2020 format-pattern="dd/MM/yyyy"

<ui5-date-picker id="myDatepicker12" min-date="1/1/2020" max-date="4/5/2020" format-pattern="dd/MM/yyyy"></ui5-date-picker>
	

DatePicker with shortcuts: type "today" or "yesterday" and press "Enter"

<ui5-date-picker></ui5-date-picker>
	

DatePicker with format-pattern='short'

<ui5-date-picker format-pattern='short'></ui5-date-picker>
	

DatePicker with format-pattern='long'

<ui5-date-picker format-pattern='long'></ui5-date-picker>
	

DatePicker with format-pattern='QQQ yyyy, MMM dd', value='Q4 2018, Feb 14'

<ui5-date-picker format-pattern='QQQ yyyy, MMM dd' value='Q4 2018, Feb 14'></ui5-date-picker>
	

DatePicker with format-pattern='EEE, M/d/yyyy'

<ui5-date-picker format-pattern='EEE, M/d/yyyy'></ui5-date-picker>
	

Disabled DatePicker

<ui5-date-picker disabled value="8 September 2021"></ui5-date-picker>
	

readonly DatePicker

<ui5-date-picker readonly value="8 September 2021"></ui5-date-picker>
	

DatePicker with Japanese Calendar Type

<ui5-date-picker primary-calendar-type='Japanese'></ui5-date-picker>
	

DatePicker with Islamic Calendar Type

<ui5-date-picker primary-calendar-type='Islamic'></ui5-date-picker>
	

DatePicker with Buddhist Calendar Type

<ui5-date-picker primary-calendar-type='Buddhist'></ui5-date-picker>
	

DatePicker with Persian Calendar Type

<ui5-date-picker primary-calendar-type='Persian'></ui5-date-picker>
	

DatePicker with primary and secondary calendar type

<ui5-date-picker primary-calendar-type='Islamic' secondary-calendar-type='Gregorian'></ui5-date-picker>

Overview

The ui5-date-picker component provides an input field with assigned calendar which opens on user action. The ui5-date-picker allows users to select a localized date using touch, mouse, or keyboard input. It consists of two parts: the date input field and the date picker.

Usage

The user can enter a date by:
  • Using the calendar that opens in a popup
  • Typing it in directly in the input field


When the user makes an entry and presses the enter key, the calendar shows the corresponding date. When the user directly triggers the calendar display, the actual date is displayed.

Formatting

If a date is entered by typing it into the input field, it must fit to the used date format.

Supported format options are pattern-based on Unicode LDML Date Format notation. For more information, see UTS #35: Unicode Locale Data Markup Language.

For example, if the format-pattern is "yyyy-MM-dd", a valid value string is "2015-07-30" and the same is displayed in the input.

Keyboard Handling

The ui5-date-picker provides advanced keyboard handling. If the ui5-date-picker is focused, you can open or close the drop-down by pressing F4, ALT+UP or ALT+DOWN keys. Once the drop-down is opened, you can use the UP, DOWN, LEFT, RIGHT arrow keys to navigate through the dates and select one by pressing the Space or Enter keys. Moreover you can use TAB to reach the buttons for changing month and year.
If the ui5-date-picker is focused and the picker dialog is not opened the user can increment or decrement the corresponding field of the JS date object referenced by dateValue propery by using the following shortcuts:
  • [PAGEDOWN] - Decrements the corresponding day of the month by one
  • [SHIFT] + [PAGEDOWN] - Decrements the corresponding month by one
  • [SHIFT] + [CTRL] + [PAGEDOWN] - Decrements the corresponding year by one
  • [PAGEUP] - Increments the corresponding day of the month by one
  • [SHIFT] + [PAGEUP] - Increments the corresponding month by one
  • [SHIFT] + [CTRL] + [PAGEUP] - Increments the corresponding year by one

Calendar types

The component supports several calendar types - Gregorian, Buddhist, Islamic, Japanese and Persian. By default the Gregorian Calendar is used. In order to use the Buddhist, Islamic, Japanese or Persian calendar, you need to set the primaryCalendarType property and import one or more of the following modules:

import "@ui5/webcomponents-localization/dist/features/calendar/Buddhist.js";
import "@ui5/webcomponents-localization/dist/features/calendar/Islamic.js";
import "@ui5/webcomponents-localization/dist/features/calendar/Japanese.js";
import "@ui5/webcomponents-localization/dist/features/calendar/Persian.js";

Or, you can use the global configuration and set the calendarType key:
<script data-id="sap-ui-config" type="application/json">
{
	"calendarType": "Japanese"
}
</script>

ES6 Module Import

import "@ui5/webcomponents/dist/DatePicker";

Properties/Attributes

You can use both properties and attributes with the same effect. The name of each attribute is listed below the name of the property, if different.

Name
Type
Default Value
Description
accessibleName
accessible-name
String
Defines the aria-label attribute for the component.
since v1.0.0-rc.15
accessibleNameRef
accessible-name-ref
String
""
Receives id(or many ids) of the elements that label the component.
since v1.0.0-rc.15
dateValue (readonly)
date-value
Date
Currently selected date represented as a Local JavaScript Date instance.
disabled
boolean
false
Determines whether the component is displayed as disabled.
hideWeekNumbers
hide-week-numbers
boolean
false
Defines the visibility of the week numbers column.

Note: For calendars other than Gregorian, the week numbers are not displayed regardless of what is set.
since v1.0.0-rc.8
name
string
""
Determines the name with which the component will be submitted in an HTML form.

Important: For the name property to have effect, you must add the following import to your project: import "@ui5/webcomponents/dist/features/InputElementsFormSupport.js";

Note: When set, a native input HTML element will be created inside the component so that it can be submitted as part of an HTML form. Do not use this property unless you need to submit a form.
placeholder
string
undefined
Defines a short hint, intended to aid the user with data entry when the component has no value.

Note: When no placeholder is set, the format pattern is displayed as a placeholder. Passing an empty string as the value of this property will make the component appear empty - without placeholder or format pattern.
readonly
boolean
false
Determines whether the component is displayed as read-only.
required
boolean
false
Defines whether the component is required.
since v1.0.0-rc.9
value
string
""
Defines a formatted date value.
valueState
value-state
ValueState
"None"
Defines the value state of the component.

Available options are:
  • None
  • Error
  • Warning
  • Success
  • Information
formatPattern
format-pattern
string
""
Determines the format, displayed in the input field.
maxDate
max-date
string
""
Determines the maximum date available for selection.
since v1.0.0-rc.6
minDate
min-date
string
""
Determines the minimum date available for selection.
since v1.0.0-rc.6
primaryCalendarType
primary-calendar-type
CalendarType
Sets a calendar type used for display. If not set, the calendar type of the global configuration is used.
secondaryCalendarType
secondary-calendar-type
CalendarType
undefined
Defines the secondary calendar type. If not set, the calendar will only show the primary calendar type.
since v1.0.0-rc.16

Slots

This Element provides slot(s). This means it can display its child nodes.
Unless targeting the default slot, use the slot attribute to define the destination slot for each child.
Text, along with HTML Elements with no slot attribute, goes the the default slot.

Slot
Type
Description
valueStateMessage
HTMLElement
Defines the value state message that will be displayed as pop up under the component.

Note: If not specified, a default text (in the respective language) will be displayed.
Note: The valueStateMessage would be displayed, when the component is in Information, Warning or Error value state.

Events

This Web Component fires semantic events upon user interaction. You can bind to these events with the standard DOM APIs, such as addEventListener.

Name
Description
change
Fired when the input operation has finished by pressing Enter or on focusout.
value
type: String
description: The submitted value.
valid
type: Boolean
description: Indicator if the value is in correct format pattern and in valid range.
input
Fired when the value of the component is changed at each key stroke.
value
type: String
description: The submitted value.
valid
type: Boolean
description: Indicator if the value is in correct format pattern and in valid range.

Methods

This Web Component exposes public methods. You can invoke them directly on the Web Component instance.

Name
Description
closePicker
Closes the picker.
formatValue
Formats a Java Script date object into a string representing a locale date according to the formatPattern property of the DatePicker instance
date
type: object
description: A Java Script date object to be formatted as string
isInValidRange
Checks if a date is between the minimum and maximum date.
value
type: string
description: A value to be checked
isOpen
Checks if the picker is open.
isValid
Checks if a value is valid against the current date format of the DatePicker.
value
type: string
description: A value to be tested against the current date format
openPicker
Opens the picker.
Theme: Quartz Light Quartz Dark Quartz High Contrast Black Quartz High Contrast White Belize High Contrast Black High Contrast White Horizon
Content Density: Cozy Compact
Text Direction: LTR RTL
Apply Cancel