Vue Datepicker Documentation

repository·main·Indexed 23 days ago

https://github.com/vuepic/vue-datepicker

A comprehensive and highly configurable datepicker component library for Vue 3 applications. It supports various picker types including single date, range, time, month, year, quarter, and week, as well as UTC, timezones, and SSR. The library features built-in dark and light themes customizable via CSS variables and provides a wide range of programmatic methods and events for deep integration.

Tokens
46.1K
Snippets
157
Records
192
Agent score
82%

What's inside @vuepic/vue-datepicker

  1. Overview of Vue Datepicker

    main

    Vue Datepicker is a lightweight and powerful datepicker solution designed specifically for Vue 3. It is highly customizable via props, slots, and custom components, allowing it to fit into almost any project requirement.

    Key features include:

    • Multiple Modes: Supports timepicker, range picker, month-year picker, week numbers, and more.
    • Modular Design: Provides a wide range of features while allowing deep customization for specific needs.
    • Customization: Fully accessible, mobile-friendly, supports built-in dark and light modes, and uses customizable CSS variables.
    • Input Options: Supports various input types including text input.
  2. Overview of @vuepic/vue-datepicker features

    main

    The @vuepic/vue-datepicker is a highly configurable datepicker solution for Vue 3. Key features include:

    • Picker Types: Single date, range, time, month, year, quarter, and week pickers.
    • Selection Modes: Multiple dates select and multiple calendars.
    • Advanced Support: UTC support, timezones, locale support, and SSR support.
    • UI/UX: Text input, dark and light themes, week numbers, and accessibility.
    • Developer Experience: Custom v-model support and included TypeScript definitions.
  3. Use `TZDate` for precise timezone handling

    main

    To ensure the datepicker matches the provided time exactly without conversion shifts, use the TZDate object exported by @vuepic/vue-datepicker. When a user selects a date in a datepicker configured with a timezone, the v-model value will be a TZDate object.

    Important Note on retrieving values: Because TZDate inherits from the standard Date object, console.log(date) may show the date in the local system timezone, while date.toString() will return the value in the specific timezone configured in the datepicker. To retrieve the date value in the intended timezone, always call date.toString().

    <template>
      <VueDatepicker v-model="date" timezone="utc" />
    </template>
    
    <script lang="ts" setup>
      import { VueDatepicker, TZDate } from '@vuepic/vue-datepicker';
      import { ref } from "vue";
      
      const date = ref(new TZDate('Sat Oct 25 2025 19:28:21 GMT+0200 (Central European Summer Time)', 'utc'));
    </script>
  4. Remove 'partial' property from flow prop in v14

    main

    The partial property within the flow prop has been removed in v14 because it no longer affects behavior. Previously, it was used in specific scenarios with auto-apply, but this is now handled automatically. While the flow prop remains an object to allow for future updates, you should remove the partial key from your configuration.

    <template>
      <VueDatePicker
        ref="dpRef"
        :flow="{
          steps: ['year', 'month', 'calendar']
          // partial: true, <-- Remove this
        }"
        @flow-step="onFlowStep"
      />
    </template>
  5. Migrate flow methods from v13 to v14

    main

    In v14, the exposed method for controlling the datepicker flow has been renamed and its parameter type has changed:

    1. Rename: handleFlow is now executeFlow.
    2. Parameter Change: Instead of passing a numeric step index, you must now pass the step value (of type PickerSection).

    Example of the updated usage:

    // v13 (Deprecated/Removed)
    dpRef.value?.handleFlow(1);
    
    // v14
    dpRef.value?.executeFlow('month');
    dpRef.value?.executeFlow('month');
  6. Update @flow-step event handler for v14

    main

    The @flow-step emitted event has changed its payload. In v13, it provided the step index (a number). In v14, it provides the step value (the PickerSection type).

    Update your event handler signatures accordingly:

    // v13
    function onFlowStep(stepIndex: number) {}
    
    // v14
    function onFlowStep(step: PickerSection) {}
    function onFlowStep(step: PickerSection) {}
  7. Access Datepicker methods via template refs

    main

    To call methods on the VueDatePicker component from your script, you must add a ref to the component in your template and access it using Vue's ref or useTemplateRef API. This allows you to trigger internal component logic like opening/closing menus or clearing values from external buttons or functions.

    <template>
      <VueDatePicker v-model="date" ref="datepicker" />
    </template>
    
    <script lang="ts" setup>
      import { VueDatePicker } from "@vuepic/vue-datepicker";
      import { ref, useTemplateRef } from 'vue';
    
      const date = ref();
      const dpRef = useTemplateRef<InstanceType<typeof VueDatePicker>>('datepicker');
    
      const yourCustomMethod = () => {
        dpRef.value?.closeMenu()
      }
    </script>
  8. Register VueDatePicker globally

    main

    To use the VueDatePicker component anywhere in your application without local imports, register it in your main entry file (e.g., main.js or app.js). You must also import the component's CSS file.

    import { createApp } from 'vue';
    import App from './App.vue';
    
    import { VueDatePicker } from '@vuepic/vue-datepicker';
    import '@vuepic/vue-datepicker/dist/main.css';
    
    const app = createApp(App);
    app.component('VueDatePicker', VueDatePicker);
  9. Install @vuepic/vue-datepicker

    main

    You can install the datepicker package using any of the following package managers:

    # npm
    npm install @vuepic/vue-datepicker
    
    # yarn
    yarn add @vuepic/vue-datepicker
    
    # pnpm
    pnpm add @vuepic/vue-datepicker
    
    # bun
    bun add @vuepic/vue-datepicker