Skip to content
On this page

Introduction

This is a reimplementation of vuejs-datepicker in Vue 3 and with greatly cleaned up code.

All date manipulation and formatting are done via the amazing date-fns library, so it's a direct dependency of this picker.

Example

Datepicker comes with styling, but input itself does not. Attributes fall through to the input element, so you can use classes and styles as you would on any input.

Installation

Package is available on NPM: npm

sh
npm i vue3-datepicker

Then import it in your code and use as a usual component:

vue
<script setup>
import Datepicker from 'vue3-datepicker'
import { ref } from 'vue'
const picked = ref(new Date())
</script>

<template>
  <Datepicker v-model="picked" />
</template>

Compatibility

Package is transpiled and should be usable for everyone with ES6 and above, but the styling of the datepicker itself uses CSS Grid and CSS variables.

Package uses typescript and ships with TS declarations for its components.

Props and attributes

Attribute fallthrough is enabled, so any attribute you apply to the component will be passed down to the input.

All props which accept formatting strings for dates use date-fns formatting function under the hood, so see that function's documentation for patterns.

Main interaction to date selection is done via v-model with Date as expected type of the value passed.

More in-depth documentation of the props, as well as examples, can be found in Configuration

IDTypeDefaultDescription
upperLimitDateUpper limit for available dates for picking
lowerLimitDateLower limit for available dates for picking
startingViewDateDate() => new Date()Date on which to focus when empty datepicker is opened. Default is "right now"
disabledDates{ dates: Date[] }Dates not available for picking
disabledTime{ dates: Date[] }Dates not available for time picking
startingView'time' | 'day' | 'month' | 'year'`'day'View on which the date picker should open. Can be either year, month, or day
minimumView'time' | 'day' | 'month' | 'year'`'day'If set, lower-level views won't show
dayPickerHeadingFormatStringLLLL yyyydate-fns-type formatting for a day view heading
dayFormatStringdddate-fns-type formatting for each day on the day view
weekdayFormatStringEEdate-fns-type formatting for a line of weekdays on day view
inputFormatStringyyyy-MM-dddate-fns-type format in which the string in the input should be both parsed and displayed
localeLocaledate-fns/locale/endate-fns locale object. Used in string formatting (see default dayPickerHeadingFormat)
disabledBooleanfalseDisables datepicker and prevents it's opening
typeableBooleanfalseAllows user to input date manually
weekStartsOnNumber1Day on which the week should start. Number from 0 to 6, where 0 is Sunday and 6 is Saturday. Week starts with a Monday (1) by default
clearableBooleanfalseAllows clearing the selected date and setting the value to null
allowOutsideIntervalBooleanfalseAllows user to click dates outside of current interval

Events

  • opened: Emitted every time the popup opens, including on field focus
  • closed: Emitted every time the popup closes, including on field blur
  • decadePageChanged: Emitted when a page is changed on the year picker view, displaying a different decade. Has a date that is included in the shown decade as an argument.
  • yearPageChanged: Emitted when a page is changed on the month picker view, displaying a different year. Has a date that is included in the shown year as an argument.
  • monthPageChanged: Emitted when a page is changed on the day picker view, displaying a different month. Has a date that is included in the shown month as an argument.

Styling

Styling is done via CSS variables, which control colors used in the popup. All variables, as well as styling example and playground can be found in Configuration section