Vue CTK Date Time Picker
Vue CTK Date Time Picker is a flexible Vue.js component for selecting dates and times, offering both single-date and range selection modes. Its current stable version is 2.6.1. The package maintains an active release cadence, frequently delivering bug fixes and new features, especially since Chronotruck took over its maintenance around version 2.2.0. Key differentiators include built-in dark mode, support for custom shortcuts with callback functions, compatibility with Nuxt.js, locale reactivity, and granular control over disabled dates and keyboard navigation. It is designed to be highly configurable, supporting various date and time formats and offering both ESM/CommonJS and UMD distributions for different project setups.
Common errors
-
Cannot read properties of undefined (reading 'scrollTop')
cause An internal issue related to scrolling logic within the component, particularly when elements might not be fully rendered or are inaccessible.fixUpdate `vue-ctk-date-time-picker` to version 2.5.0 or newer, where this specific 'scrollTop' error was addressed. -
Invalid date
cause Occurred when the date parsing logic encountered an unrecognized or improperly formatted date string, or when certain interaction behaviors led to an invalid date state.fixEnsure that the `v-model` value adheres to expected date formats. If using a pre-2.2.0 version, update to 2.2.0 or later, as an underlying bug related to this was fixed. -
`is-hidden` event emitted multiple times
cause Due to a bug, the `is-hidden` event was sometimes emitted more than once when the picker closed, leading to redundant or incorrect side effects in parent components.fixUpgrade `vue-ctk-date-time-picker` to version 2.3.0 or higher to resolve the issue where the `is-hidden` event was incorrectly emitted multiple times.
Warnings
- breaking The behavior and configuration of 'Range shortcuts' were changed, which might require adjustments to existing implementations utilizing this feature. The exact nature of the breaking change beyond 'Range shortcuts' is not fully detailed in the changelog snippet provided but indicates a significant shift.
- breaking The behavior of clicking 'AM' or 'PM' buttons has changed. The feature allowing a double-click to add/remove 12 hours from the time selection was removed. Users accustomed to this interaction will find it no longer works.
- gotcha Prior to version 2.2.0, the component could suffer from multiple ID conflicts when several instances were rendered on the same page, leading to unpredictable behavior or styling issues.
- gotcha The `min-date` and `max-date` props now support time components. In versions prior to 2.1.0, these props primarily considered only the date part, which could lead to unexpected behavior if time constraints were implicitly assumed or desired.
- gotcha In versions before 2.0.8, changing the `locale` prop dynamically after the component was mounted would not reactively update the displayed locale. The picker would remain in its initial locale.
Install
-
npm install vue-ctk-date-time-picker -
yarn add vue-ctk-date-time-picker -
pnpm add vue-ctk-date-time-picker
Imports
- VueCtkDateTimePicker
const VueCtkDateTimePicker = require('vue-ctk-date-time-picker');import VueCtkDateTimePicker from 'vue-ctk-date-time-picker';
- CSS Styles
import 'vue-ctk-date-time-picker/vue-ctk-date-time-picker.css';
import 'vue-ctk-date-time-picker/dist/vue-ctk-date-time-picker.css';
- Global Component Registration
Vue.component('vue-ctk-date-time-picker', VueCtkDateTimePicker);Vue.component('VueCtkDateTimePicker', VueCtkDateTimePicker);
Quickstart
import { createApp, ref } from 'vue';
import VueCtkDateTimePicker from 'vue-ctk-date-time-picker';
import 'vue-ctk-date-time-picker/dist/vue-ctk-date-time-picker.css';
const app = createApp({
components: {
VueCtkDateTimePicker
},
setup() {
const selectedDateTime = ref(null);
const selectedRange = ref({
start: null,
end: null
});
return {
selectedDateTime,
selectedRange
};
},
template: `
<div>
<h2>Single Date/Time Picker</h2>
<VueCtkDateTimePicker
v-model="selectedDateTime"
label="Select Date & Time"
:minute-interval="15"
/>
<p>Selected: {{ selectedDateTime }}</p>
<h2>Range Date/Time Picker</h2>
<VueCtkDateTimePicker
v-model="selectedRange"
:range="true"
label="Select Date Range"
output-format="YYYY-MM-DD"
/>
<p>Start: {{ selectedRange.start }}</p>
<p>End: {{ selectedRange.end }}</p>
</div>
`
});
app.mount('#app');