Skip to content

Datepicker

A date picker component which allows the selection of a single date. Wraps a date-input component (unless the has-input property is set to false)

Default Component

html
<datepicker v-model="pickedDate" />

Result

Customized Component

This example

  • swaps the day names
  • limits the selectable dates to a 7-day range around the current date
  • starts the week with Mondays
html
<datepicker
    v-model="pickedDate"
    :day-names="'Su Mo Tu We Th Fr Sa'.split(' ')"
    :valid-from="from"
    :valid-until="to"
    :start-of-week-index="1"
/>

Result

Date Format and Localization

The input-format and output-format properties are passed on the date-input component and interpreted there.

html
<datepicker
    v-model="pickedDate"
    locale="en-US"
    input-format="MM/DD/YYYY"
    output-format="MM/DD/YYYY"
/>

Result

Component Without Toggle (and Input)

html
<datepicker
    v-model="pickedDate"
    :has-input="false"
/>

Result

October
S
M
T
W
T
F
S

Component Allowing More Than a Single Value

Two values and highlighting the range between them.

html
<datepicker
    v-model="dateRange"
    :max-number-of-values="2"
    :highlight-range="true"
/>

Result

October
S
M
T
W
T
F
S
[
  "2024-09-28T18:41:40.522Z",
  "2024-10-05T18:41:40.522Z"
]

Ten values which can be toggled randomly.

html
<datepicker
    v-model="dateRangeLarge"
    :max-number-of-values="10"
    :shown-month="new Date('2024-06-05')"
/>

Result

June
S
M
T
W
T
F
S
[]

Properties

Properties of the dateInput component can be declared and are passed on.

NameTypeDefaultDescription
modelValueDateThe selected date
shownMonthDateThe month displayed when opening the datepicker; defaults to the current month when not set
maxNumberOfValuesNumber1Determines how many dates you can pick; values greater than one hasInput will be ignored, no date input will be provided and picked dates can be "toggled" on and off
validFromDateWhen set dates before this date can not be selected
validUntilDateWhen set dates after this date can not be selected
highlightRangeBooleanWith maxNumberOfValuesgreater than one this will highlight all date cells between the highest and lowest date value
dayNamesArray['S', 'M', 'T', 'W', 'T', 'F', 'S', 'S']An array with day names used for labelling the dates grid
localeString'default'The locale used for rendering month names
startOfWeekIndexNumber0Accepts 0 for Sunday and 1 for Monday
hasInputBooleantrueWhen true a date-input component with a toggle is rendered; when false the datepicker is always visible

Events

NameArgumentsDescription
update:modelValuepickedDate - DateEmitted when a date is clicked
month-changedsheetDate - DateEmitted when the month is changed, sheetDate is the first day of the currently displayed month
year-changedsheetDate - DateEmitted when the year is changed, sheetDate is the first day of the currently displayed month