Skip to content

Calendar

Provides calendar single selection, multiple selection, range selection, week dimension, month dimension and other functions.

Basic Usage

The default type is date, set v-model binding value (13-digit timestamp format), and listen to the @confirm event to get the selected value. The min-date minimum date defaults to 6 months before the current date, and the max-date maximum date defaults to 6 months after the current date. The calendar only displays dates between the minimum and maximum dates. The label is optional. You can set the title width through label-width, which defaults to '33%'.

Try not to set min-date and max-date too large to avoid poor page performance due to calculation and transmission of large amounts of data.

html
<wd-calendar v-model="value" label="Date Selection" @confirm="handleConfirm" />
typescript
const value = ref<number>(Date.now())
function handleConfirm({ value }) {
  console.log(value)
}

Multiple Date Selection

Set type to dates type, at this time value is an array.

html
<wd-calendar type="dates" v-model="value" @confirm="handleConfirm" />
typescript
const value = ref<number[]>([])
function handleConfirm({ value }) {
  console.log(value)
}

Week Selection

Set type to week type. If value has an initial value, it is recommended to set the week start day first-day-of-week to 1 (Monday) to avoid mismatch between selected style and display.

html
<wd-calendar type="week" v-model="value" :first-day-of-week="1" @confirm="handleConfirm" />
typescript
const value = ref<number>(Date.now())
function handleConfirm({ value }) {
  console.log(value)
}

Month Selection

Set type to month type. When value has a value, its value is the first day of the month.

html
<wd-calendar type="month" v-model="value" @confirm="handleConfirm" />
typescript
const value = ref<number>(Date.now())
function handleConfirm({ value }) {
  console.log(value)
}

Range Selection

type supports daterange (date range selection), weekrange (week range selection), monthrange (month range selection) types. At this time, value is in array format.

html
<wd-calendar type="daterange" v-model="value" @confirm="handleConfirm" />
typescript
const value = ref<number[]>([])
function handleConfirm({ value }) {
  console.log(value)
}

Date Time Type

Set type to datetime type to select down to hours, minutes, and seconds. Set type to datetimerange for range selection.

html
<wd-calendar type="datetime" v-model="value" @confirm="handleConfirm" />
typescript
const value = ref<string>("")
function handleConfirm({ value }) {
  console.log(value)
}

You can set hide-second to display time only to the minute level; set the time-filter property to customize the filtering of hour, minute, second options. This property accepts { type: string, values: array } parameters and returns a new array. The type value is 'hour', 'minute' or 'second', and values is the picker data list.

html
<wd-calendar type="datetime" v-model="value" @confirm="handleConfirm" hide-second :time-filter="timeFilter" />
typescript
const value = ref<string>("")

function timeFilter({ type, values }) {
  if (type === "minute") {
    // Only show 0,10,20,30,40,50 minute options
    return values.filter((item) => {
      return item % 10 === 0
    })
  }
  return values
}
function handleConfirm({ value }) {
  console.log(value)
}

Day/Week/Month Switch

Set the show-type-switch property to display the day/week/month switch function. It supports switching between date, week, and month types (date, week, month). You can set the initial type through the type property. If type is a range type like daterange, then the calendar can switch between daterange, weekrange, and monthrange.

html
<wd-calendar label="Day/Week/Month Switch" :first-day-of-week="1" show-type-switch v-model="value" @confirm="handleConfirm" />

Quick Operation

Set the show-confirm property to false to not display the confirm button. This is only valid for date, daterange, week, weekrange, month, monthrange types.

html
<wd-calendar label="Quick Operation" :show-confirm="false" v-model="value" @confirm="handleConfirm" />

Allow Same Day Selection in Range

Set the allow-same-day property to allow users to select the same day, same week, or same month in range selection.

html
<wd-calendar type="daterange" v-model="value" allow-same-day @confirm="handleConfirm" />

Date Formatting

Set the formatter parameter, which is a function type that receives an object parameter and returns an object. The properties of the object remain consistent with the input parameters. Its properties are as follows:

PropertyTypeDescriptionVersion
typeCalendarDayTypeSee CalendarDayType for options-
datetimestamp13-digit timestamp-
textstringDate text content-
topInfostringTop prompt information-
bottomInfostringBottom prompt information-
disabledbooleanWhether disabled-

CalendarDayType

TypeDescriptionVersion
selectedSingle date selected-
startRange start date-
endRange end date-
middleDate between range start and end-
sameRange start and end date are the same day-
currentCurrent date-
multiple-middleMultiple date range selection, dates between start and end1.5.0
multiple-selectedMultiple date range selection, selected dates1.5.0

Attributes

AttributeDescriptionTypeOptionsDefaultVersion
v-modelSelected value, 13-digit timestamp or timestamp arraynull / number / array---
typeDate typestringdate / dates / datetime / week / month / daterange / datetimerange / weekrange / monthrangedate-
min-dateMinimum date, 13-digit timestampnumber-6 months before current date-
max-dateMaximum date, 13-digit timestampnumber-6 months after current date-
first-day-of-weekWeek start daynumber-0-
formatterDate formatting functionfunction---
max-rangeMaximum date range for range selection typesnumber---
range-promptError message when selection exceeds maximum date rangestring-Selection cannot exceed x days-
allow-same-dayWhether to allow selecting the same day in range selectionboolean-false-
default-timeSpecific time of day for selected datestring / array-00:00:00-
time-filterFilter function for time picker data, effective for 'datetime' or 'datetimerange' typesfunction---
hide-secondWhether to hide second modification for 'datetime' or 'datetimerange' typesboolean-false-
show-confirmWhether to show confirm buttonboolean-true-
show-type-switchWhether to show type switch functionboolean-false-
shortcutsQuick options, array of objects with required 'text' propertyarray---
titlePopup titlestring-Select Date-
labelPicker left textstring---
placeholderPicker placeholderstring-Please select-
disabledDisabled stateboolean-false-
readonlyRead-only stateboolean-false-
display-formatCustom display text formatting function, returns a stringfunction---
inner-display-formatCustom panel internal display for range selection types, returns a stringfunction---
sizeSet picker sizestringlarge--
label-widthSet left title widthstring-33%-
errorWhether in error state, right content is red in error stateboolean-false-
requiredRequired styleboolean-false-
centerWhether to vertically centerboolean-false-
ellipsisWhether to hide overflowboolean-false-
align-rightDisplay picker value aligned to the rightboolean-false-
before-confirmValidation function before confirmation, receives { value, resolve } parameters, continue through resolve, resolve accepts a boolean parameterfunction---
close-on-click-modalWhether to close when clicking maskboolean-true-
z-indexPopup layer z-indexnumber-15-
safe-area-inset-bottomWhether to set bottom safe area for popup panel (iPhone X type devices)boolean-true-
propForm field model field name, required when using form validationstring---
rulesForm validation rules, used with wd-form componentFormItemRule []-[]-
immediate-changeWhether to trigger the picker-view's change event immediately when the finger is released. If not enabled, the change event will be triggered after the scrolling animation ends. Available from version 1.2.25, only supported on WeChat Mini Program and Alipay Mini Program.boolean-false1.2.25
with-cellWhether to use built-in cell pickerboolean-true1.5.0
clearableShow clear buttonboolean-false1.11.0
root-portalWhether to detach from the page, used to solve various fixed positioning issuesboolean-false1.11.0

FormItemRule Data Structure

KeyDescriptionType
requiredWhether required fieldboolean
messageError messagestring
validatorValidate through function, can return a Promise for async validation(value, rule) => boolean | Promise
patternValidate through regular expression, validation fails if regex doesn't matchRegExp

Events

Event NameDescriptionParametersVersion
confirmTriggered when binding value changes{ value, type }-
changeTriggered when clicking panel date{ value }-
cancelTriggered when clicking close button or mask--
openTriggered when calendar opens--
clearTriggered when clicking clear button-1.11.0

Methods

Method NameDescriptionParametersVersion
openOpen panel--
closeClose panel--

Slots

NameDescriptionVersion
defaultCustom display-
labelLeft slot-

External Classes

Class NameDescriptionVersion
custom-classRoot node style-
custom-label-classLabel external custom style-
custom-value-classValue external custom style-

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.