Skip to content

Date Picker

The date picker allows users to select a date from a calendar.

Basic Usage

//

Property Value:

vue
<template>
  <spr-date-picker id="datepicker" v-model="datePickerModel" display-helper />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');
</script>

Adding Label

//

Value: 09-11-1997

Property Value: 09-11-1997

vue
<template>
  <spr-date-picker id="datepicker" v-model="datePickerModel" label="Date Picker" display-helper format="MM-DD-YYYY"/>
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');
</script>

Custom Width

You can manually set the width of the date picker by passing the width prop.

//

Property Value:

vue
<template>
  <spr-date-picker id="datepicker" v-model="datePickerModel" label="Date Picker" width="400px" display-helper />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');
</script>

Date Format

You can specify the format of the date by passing the format prop. The default format is MM-DD-YYYY. The component will return dates in the specified format.

//

Value:

vue
<template>
  <spr-date-picker 
    id="datepicker" 
    v-model="datePickerModel" 
    label="Date with YYYY-MM-DD format" 
    format="YYYY-MM-DD" 
    display-helper 
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');
</script>
//
Value:
vue
<template>
  <spr-date-picker 
    id="datepicker" 
    v-model="datePickerModel" 
    label="Date with MM/DD/YYYY format" 
    format="MM/DD/YYYY" 
    display-helper 
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');
</script>

Disabled

Add the disabled prop to disable the date picker.

//
vue
<template>
  <spr-date-picker id="datepicker" v-model="datePickerModel" label="Date Picker" display-helper disabled />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');
</script>

Read Only

Add the readonly prop to make date picker as read only.

//
vue
<template>
  <spr-date-picker id="datepicker" v-model="datePickerModel" label="Date Picker" display-helper readonly />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('10-12-2025');
</script>

Helper Text

A helper message is a text label displayed below the input field, offering additional information such as instructions, formatting tips, or validation feedback.

To display the helper message, set the display-helper prop to true and add the helper-text prop with the message content. You can also include an icon by using the helper-icon prop, which utilizes the Iconify icon library.

Using Helper Text Directly to Props

//
This is a helper message

Property Value:

vue
<template>
  <spr-date-picker
    id="datepicker"
    class="[&>p]:spr-m-0"
    v-model="datePickerModel"
    label="Date Picker"
    helper-icon="ph:warning-circle-fill"
    helper-text="This is a helper message"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

import { Icon } from '@iconify/vue';

const datePickerModel = ref('');
</script>

Using Helper Text Slot

//
This is a helper message
vue
<template>
  <spr-date-picker id="datepicker" class="[&>p]:spr-m-0" v-model="datePickerModel" label="Date Picker" display-helper>
    <template #helperMessage>
      <span>This is a helper message</span>
    </template>
  </spr-date-picker>
</template>

<script lang="ts" setup>
import { ref } from 'vue';

import { Icon } from '@iconify/vue';

const datePickerModel = ref('');
</script>

Error State

To handle error states, add the error prop to the date picker. You can also include an icon by using the helper-icon prop, which utilizes the Iconify icon library.

Using Helper Text Directly to Props

//
This is a helper message
vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    helper-icon="ph:warning-circle-fill"
    helper-text="This is a helper message"
    display-helper
    error
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

import { Icon } from '@iconify/vue';

const datePickerModel = ref('');
</script>

Using Helper Text Slot

//
This is a helper message
vue
<template>
  <spr-date-picker id="datepicker" v-model="datePickerModel" label="Date Picker" display-helper error>
    <template #helperMessage>
      <Icon icon="ph:warning-circle-fill" width="20px" height="20px" />
      <span>This is a helper message</span>
    </template>
  </spr-date-picker>
</template>

<script lang="ts" setup>
import { ref } from 'vue';

import { Icon } from '@iconify/vue';

const datePickerModel = ref('');
</script>

Manually Set Current Year

You can manually set the current year to be shown in the calendar. The default current year is the current year. Pass the current-year prop to set the current year.

//
vue
<template>
  <spr-date-picker id="datepicker" v-model="datePickerModel" label="Date Picker" current-year="2000" display-helper />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

import { Icon } from '@iconify/vue';

const datePickerModel = ref('');
</script>

Manually Set Min-Max Year

It also allows you to manually set the minimum and maximum year to be shown in the calendar. The default minumum year is set 1900 and the maximum year is the current year.

//
vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    :min-max-year="minMaxYear"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const minMaxYear = ref({
  min: 2000,
  max: 2025,
});
</script>

Rest Days

You can set the rest days in the week by passing the rest-days prop.

The value should be an array of strings that may contain the ff:

js
const restdays = ['su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'];
//
vue
<template>
  <spr-date-picker id="datepicker" v-model="datePickerModel" label="Date Picker" :rest-days="restDays" display-helper />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const restDays = ref(['mo', 'we', 'fr', 'sa']);
</script>

Disabled Dates

You can disable specific dates by passing the disabled-dates prop. There are ways to disable dates:

Disable dates using From and To

To disable dates using From and To, pass the disabled-dates props that contains string of from and to.

from and to should be in the format MM-DD-YYYY.

//
vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    :disabled-dates="disabledDates"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const disabledDates = ref({ from: '02-12-2025', to: '05-15-2025' });
</script>

Disable Past or Future Dates

To disable past dates, pass the disabled-dates prop. that contains boolean of pastDates or futureDates set to true.

//
//
vue
<template>
  <spr-date-picker
    id="datepicker1"
    v-model="datePickerModel"
    label="Past Dates Disabled"
    :disabled-dates="disabledPastDates"
    display-helper
  />

  <spr-date-picker
    id="datepicker2"
    v-model="datePickerModel"
    label="Future Dates Disabled"
    :disabled-dates="disabledFutureDates"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const disabledPastDates = ref({ pastDates: true });

const disabledFutureDates = ref({ futureDates: true });
</script>

Disable Past or Future with Selected Date

To disable past dates, pass the disabled-dates prop. that contains date string in pastDates or futureDates.

pastDates and futureDates should be in the format MM-DD-YYYY.

//
//
vue
<template>
  <spr-date-picker
    id="datepicker1"
    v-model="datePickerModel"
    label="Date Picker"
    :disabled-dates="disabledPastDates"
    display-helper
  />

  <spr-date-picker
    id="datepicker2"
    v-model="datePickerModel"
    label="Date Picker"
    :disabled-dates="disabledFutureDates"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const disabledPastDates = ref({ pastDates: '3-14-2025' });

const disabledFutureDates = ref({ futureDates: '3-14-2025' });
</script>

Disable Selected Dates

To disable selected dates, pass the disabled-dates prop. that contains array of selectedDates set to true.

selectedDates should be in the format MM-DD-YYYY.

//
vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    :disabled-dates="disabledDates"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const disabledDates = ref({ selectedDates: ['3-14-2025', '3-15-2025', '3-25-2025', '3-28-2025'] });
</script>

Disable Weekends

To disable weekends, pass the disabled-dates prop. that contains boolean of weekends set to true.

//
vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    :disabled-dates="disabledDates"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const disabledDates = ref({ weekends: true });
</script>

Disable Weekdays

To disable weekdays, pass the disabled-dates prop. that contains boolean of weekdays set to true.

//
vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    :disabled-dates="disabledDates"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const disabledDates = ref({ weekdays: true });
</script>

Disable Selected Days

To disable selected days, pass the disabled-dates prop. that contains array of selectedDays.

The array should contain the following values:

js
const selectedDays = ['su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'];
//
vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    :disabled-dates="disabledDates"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const disabledDates = ref({ selectedDays: ['su', 'we', 'th', 'sa'] });
</script>

Pre-selected Date

You can pre-select a date by just adding value in your v-model. The value should be in the format MM-DD-YYYY.

//
vue
<template>
  <spr-date-picker id="datepicker" v-model="datePickerModel" label="Date Picker" display-helper />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('09-11-1997');
</script>

Get Date Formats

To get the date formats, you can use the @get-date-formats emits. When the date is valid it will return a different formats.

Output:
{}
//
vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    @get-date-formats="getDateFormats"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const getDateFormats = (date) => {
  console.log(date);
};
</script>

Get Month Lists

To get the month lists used, you can use the @get-month-lists emits.

//
Output:
[]
vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    @get-month-list="getMonthList"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const getMonthList = (date) => {
  console.log(date);
};
</script>

Get Year Lists

To get the year lists used, you can use the @get-year-lists emits.

//
Output:

[]

vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    @get-year-list="getYearList"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const getYearList = (date) => {
  console.log(date);
};
</script>

Error Handling

Since there is existing error handling for the date picker, you can use the @get-date-errors emit to get the list of component-level error validations.

List of component-level error validations:

  • Validate Date if it is valid MMM/DD/YYYY
  • Validate Date Year if it is under min and max year
Output:
[]
//
vue
<template>
  <spr-date-picker
    id="datepicker"
    v-model="datePickerModel"
    label="Date Picker"
    @get-date-errors="getDateErrors"
    display-helper
  />
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const datePickerModel = ref('');

const getDateErrors = (errors) => {
  console.log(errors);
};
</script>

Popper Strategy

The Popper strategy is primarily used when working with elements like modal. It helps control the positioning behavior of popper. The strategy ensures that the popper element is dynamically positioned based on the viewport, the reference element, or other factors such as scrolling or resizing.

By default, the Popper strategy is set to absolute, which positions the popper element relative to the nearest positioned ancestor (usually the body element). However, you can change the strategy to fixed, which positions the popper element relative to the viewport, ensuring that it remains in place even when the page is scrolled.

Pass the prop popper-strategy to change the behavior position of the popper.

vue
<template>
  <spr-button tone="success" @click="modalModel = true">Open Modal</spr-button>

  <spr-modal v-model="modalModel" title="Date Picker with Modal">
    <spr-date-picker
      id="datepicker"
      v-model="datePickerModel"
      label="Date Picker"
      popper-strategy="fixed"
      display-helper
    />
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore
      magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
      consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
      Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </p>
  </spr-modal>
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const modalModel = ref(false);

const datePickerModel = ref('');
</script>

API Reference

PropertyDescriptionTypeDefault
idRequired to bind popper within the datepickerString-
v-modelBinds the selected date valueString-
labelLabel text for the input fieldString-
widthSets the width of the inputString400px
formatFormat for the selected date (e.g., 'MM-DD-YYYY', 'YYYY-MM-DD', 'MM/DD/YYYY')StringMM-DD-YYYY
disabledDisables the date pickerBooleanfalse
readonlyMakes the date picker read-onlyBooleanfalse
helper-textDisplays a helper message below the inputString-
helper-iconIcon to display alongside the helper messageString-
display-helperShows the helper messageBooleanfalse
errorIndicates that there is an error with the inputBooleanfalse
current-yearSets the current year in the calendar viewString2025
min-max-yearSets the minimum and maximum years in the calendarObject{ min: 1900, max: 2025 }
rest-daysArray of days to be treated as rest daysArray[]
disabled-datesDisables specific dates or date rangesObject{}
placementChanges the placement of the dropdown popper (e.g., `bottom`, `top`, `left`, `right`)string`bottom`
@get-input-valueEmits the actual date that is being typed or select on the datepickkerFunction-
@get-date-formatsEmits the available date formatsFunction-
@get-month-listEmits the list of monthsFunction-
@get-year-listEmits the list of yearsFunction-
@get-date-errorEmits the available date errorsFunction-

Product Uses

Sprout HR