Date Picker is an input field that allows the user to enter a date by typing or by selecting from a calendar overlay.

Note
Work In Progress

The Java examples for this component are currently in progress. In the meantime, you can view the previous examples.

<vaadin-date-picker label="Start date"></vaadin-date-picker>

The date can be entered directly using the keyboard in the format of the current locale or through the date picker overlay. The overlay opens when the field is clicked and/or any input is entered when the field is focused.

Common Input Field Features

Date Picker includes all Text Field and shared input field features.

Validation

Min & Max Value

The valid input range of Date Picker can be restricted by defining min and max values. Dates before the min and after the max are disabled in the overlay. A helper text can be used to inform the user about the accepted range.

<vaadin-date-picker
  .min="${this.today}"
  .max="${this.upperLimit}"
  label="Appointment date"
  helper-text="Must be within 60 days from today"
></vaadin-date-picker>

Custom Validation

Date Picker supports custom validation, such as limiting the options to Monday through Friday.

<vaadin-date-picker
  label="Meeting date"
  helper-text="Mondays-Fridays only"
  ...="${field(this.binder.model.startDate)}"
></vaadin-date-picker>

Week Numbers

Week numbers (ISO-8601) can be enabled in the calendar overlay. This works only when the first day of the week is set to Monday.

firstUpdated() {
  if (this.datePicker) {
    this.datePicker.i18n = {
      ...this.datePicker.i18n,
      firstDayOfWeek: 1,
    };
  }
}

render() {
  return html`
    <vaadin-date-picker label="Vacation start date" show-week-numbers></vaadin-date-picker>
  `;
}

Initial Position

Date Picker’s initial position parameter defines which date is focused in the calendar overlay when the overlay is opened. The default initial position is the selected or current date.

Use this feature to minimise the need for unnecessary navigation and/or scrolling when the user’s input is expected to be within a certain time.

<vaadin-date-picker
  label="Q4 deadline"
  .initialPosition="${formatISO(this.lastDayOfTheYear, { representation: 'date' })}"
></vaadin-date-picker>

Auto Open

The overlay automatically opens when the field is focused. This can be prevented, to have the overlay only open when the toggle button or Up/Down arrow keys are pressed. Note, that the behavior is not affected on touch devices.

<vaadin-date-picker label="Start date" auto-open-disabled></vaadin-date-picker>

Usage Patterns

Date Range

You can create a date range picker using two Date Pickers.

<vaadin-date-picker
  label="Departure date"
  @value-changed="${(e: DatePickerValueChangedEvent) =>
    (this.departureDate = e.detail.value)}"
  .max="${this.returnDate}"
></vaadin-date-picker>
<vaadin-date-picker
  label="Return date"
  @value-changed="${(e: DatePickerValueChangedEvent) => (this.returnDate = e.detail.value)}"
  .min="${this.departureDate}"
></vaadin-date-picker>

To disable the days before the start date in the end date picker, you need to handle the selection in the start date picker and change the range in the end date picker.

Best Practises

Picking vs Typing

The calendar overlay is useful when the users need to choose a day that is close to the current date or when information such as day of the week, week number, and valid dates, etc. can aid in choosing the best option.

For days well in the past or future, and for known dates such as birthdays, typing the date in the input field can be the faster and easier approach. Because of this, it is important to verify that the user can enter dates according to their locale.

Instead of a Date Picker, you can use individual input fields for day, month, and year, to improve usability on small touch devices.

<vaadin-combo-box label="Day" .items="${this.days}" style="width: 5em;"></vaadin-combo-box>
<vaadin-combo-box
  label="Month"
  .items="${this.months}"
  style="width: 9em;"
></vaadin-combo-box>
<vaadin-combo-box label="Year" .items="${this.years}" style="width: 6em;"></vaadin-combo-box>

Show the Date Format

Use a placeholder or helper to show how the input should be formatted. For example, 12/6/2020 represents different dates for Americans and Europeans.

<vaadin-date-picker
  label="Start date"
  placeholder="DD/MM/YYYY"
  helper-text="Format: DD/MM/YYYY"
></vaadin-date-picker>

Helpers are preferable to placeholders, as they are always visible. Fields with placeholders are also less noticeable than empty fields and susceptible to being skipped. Use placeholders when space is limited, for example, when Date Picker is used as a filter in a data grid header.

ComponentUsage recommendations

Time Picker

Input field for entering or selecting a specific time.

Date Time Picker

Input field for selecting both a date and a time.