Datepicker

An input with a simple dropdown/modal for selecting a date, uses native datepicker for mobile

<template>
    <section>
        <b-field>
            <div class="control">
                <b-switch v-model="showWeekNumber">Show week number</b-switch>
            </div>
        </b-field>
        <b-field label="Select a date">
            <b-datepicker
                :show-week-number="showWeekNumber"
                placeholder="Click to select..."
                icon="calendar-today">
            </b-datepicker>
        </b-field>
    </section>
</template>

<script>
export default {
    data() {
        return {
            showWeekNumber: false
        }
    }
}
</script>


# Editable (non readonly)

Use editable prop to let the user type a date.

Note that the default date parser is Date.parse() and it only works for mm-dd-yyyy format. If your locale is different, you have to pass a custom one with date-parser prop, or by setting a constructor option.
<template>
    <b-field label="Select a date">
        <b-datepicker
            placeholder="Type or select a date..."
            icon="calendar-today"
            editable>
        </b-datepicker>
    </b-field>
</template>

# Range

You can limit the date range with min-date and max-date props.

<template>
    <b-field label="Select a date">
        <b-datepicker
            placeholder="Click to select..."
            :min-date="minDate"
            :max-date="maxDate">
        </b-datepicker>
    </b-field>
</template>

<script>
    export default {
        data() {
            const today = new Date()

            return {
                date: new Date(),
                minDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 5),
                maxDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 5)
            }
        }
    }
</script>

Any slots are added to the footer of the datepicker.

<template>
    <b-field label="Select a date">
        <b-datepicker v-model="date"
            :first-day-of-week="1"
            placeholder="Click to select...">

            <button class="button is-primary"
                @click="date = new Date()">
                <b-icon icon="calendar-today"></b-icon>
                <span>Today</span>
            </button>

            <button class="button is-danger"
                @click="date = null">
                <b-icon icon="close"></b-icon>
                <span>Clear</span>
            </button>
        </b-datepicker>
    </b-field>
</template>

<script>
    export default {
        data() {
            return {
                date: new Date()
            }
        }
    }
</script>

You can add your custom header to the datepicker.

<template>
    <b-field label="Select a date">
        <b-datepicker :focused-date="date"
            :first-day-of-week="1"
            placeholder="Click to select...">

            <template slot="header">
                <b-field>
                    <b-autocomplete
                        open-on-focus
                        readonly
                        v-model="month"
                        :data="months"
                        field="name"
                        @select="selectMonth">
                    </b-autocomplete>
                    <p class="control">
                        <span class="button is-static">{{ date.getFullYear() }}</span>
                    </p>
                </b-field>
            </template>

        </b-datepicker>
    </b-field>
</template>

<script>
    export default {
        data() {
            return {
                date: new Date(),
                month: null,
                months: [
                    { name: 'January', value: 0 },
                    { name:'February', value: 1 },
                    { name:'March', value: 2 },
                    { name:'April', value: 3 },
                    { name:'May', value: 4 },
                    { name:'June', value: 5 },
                    { name:'July', value: 6 },
                    { name:'August', value: 7 },
                    { name:'September', value: 8 },
                    { name:'October', value: 9 },
                    { name:'November', value: 10 },
                    { name:'December', value: 11 }
                ]
            }
        },
        methods: {
            selectMonth(option) {
                if (option) {
                    this.date = new Date(this.date)
                    this.date.setMonth(option.value)
                }
            }
        },
        mounted() {
            this.month = this.months.filter((item) =>
                item.value == this.date.getMonth()
            )[0].name
        }
    }
</script>

# Month picker

New! 0.7.7
<template>
    <b-field label="Select a date">
        <b-datepicker
            type="month"
            placeholder="Click to select..."
            icon="calendar-today">
        </b-datepicker>
    </b-field>
</template>

# Programmatically opening

New! 0.7.7
<template>
    <section>
        <b-field>
            <b-datepicker
                ref="datepicker"
                expanded
                placeholder="Select a date">
            </b-datepicker>
            <b-button
                @click="$refs.datepicker.toggle()"
                icon-left="calendar-today"
                type="is-primary" />
        </b-field>
    </section>
</template>

# Inline

Datepicker can also be shown inline with the inline prop, input is removed, set a v-model to get the date.

<template>
    <b-datepicker v-model="date" 
        inline 
        :unselectable-days-of-week="[0, 6]">
    </b-datepicker>
</template>

<script>
    export default {
        data() {
            return {
                date: new Date()
            }
        }
    }
</script>

# Events

Dates can be passed to the datepicker with the events prop and shown with indicators.

<template>
    <span>
        <b-field>
            <b-switch v-model="bars">Bars</b-switch>
        </b-field>
        <b-datepicker
            inline
            v-model="date"
            :events="events"
            :indicators="indicators"
            >
        </b-datepicker>
    </span>
</template>

<script>
    const thisMonth = new Date().getMonth()

    export default {
        computed: {
            indicators() {
                return this.bars ? 'bars' : 'dots'
            }
        },
        data() {
            return {
                date: new Date(2017, thisMonth, 1),
                events: [
                    new Date(2017, thisMonth, 2),
                    new Date(2017, thisMonth, 6),
                    {
                        date: new Date(2017, thisMonth, 6),
                        type: 'is-info'
                    },
                    {
                        date: new Date(2017, thisMonth, 8),
                        type: 'is-danger'
                    },
                    {
                        date: new Date(2017, thisMonth, 10),
                        type: 'is-success'
                    },
                    {
                        date: new Date(2017, thisMonth, 10),
                        type: 'is-link'
                    },
                    new Date(2017, thisMonth, 12),
                    {
                        date: new Date(2017, thisMonth, 12),
                        type: 'is-warning'
                    },
                    {
                        date: new Date(2017, thisMonth, 16),
                        type: 'is-danger'
                    },
                    new Date(2017, thisMonth, 20),
                    {
                        date: new Date(2017, thisMonth, 29),
                        type: 'is-success'
                    },
                    {
                        date: new Date(2017, thisMonth, 29),
                        type: 'is-warning'
                    },
                    {
                        date: new Date(2017, thisMonth, 29),
                        type: 'is-info'
                    }
                ],
                bars: false
            }
        }
    }
</script>

# Select a range of dates

New!

Dates selected can be within a range.

<template>
    <b-field label="Select a date">
        <b-datepicker
            placeholder="Click to select..."
            v-model="dates"
            range>
        </b-datepicker>
    </b-field>
</template>

<script>
export default {
    data() {
        return {
            dates: []
        }
    }
}
</script>

# Select multiple dates

New!

Multiple dates can be selected and don't have to be contiguous.

<template>
    <b-field label="Select a date">
        <b-datepicker
            placeholder="Click to select..."
            v-model="dates"
            multiple>
        </b-datepicker>
    </b-field>
</template>

<script>
export default {
    data() {
        return {
            dates: []
        }
    }
}
</script>

# API

Name
Description
Type
Values
Default
v-modelBinding value Date
date-formatterFunction to format date to a string for display in the input Function (date) => date.toLocaleDateString()
date-parserFunction to parse string to a date for set a date from the input to the component Function (date) => new Date(Date.parse(date))
date-creatorFunction used internally to create a new Date instance Function () => new Date()
min-dateEarliest date available for selection Date
max-dateLatest date available for selection Date
eventsDates to display indicators Array
indicatorsShape to use when showing event indicators String dots, barsdots
focused-dateDate that should be initially focused upon Date new Date()
sizeVertical size of input and picker, optional String is-small, is-medium, is-large
inlineDatepicker is shown inline, input is removed Boolean false
editableEnable input/typing. Note that you might have to set a custom date parser Boolean false
loadingAdd the loading state to the input Boolean false
iconIcon name to be added String
icon-packIcon pack to use String mdi, fa, fas, far, fad, falmdi
icon-prevIcon to use for previous month String chevron-left
icon-nextIcon to use for next month String chevron-right
unselectable-datesArray of unselectable dates Array -
unselectable-days-of-weekArray of unselectable days of week Array 0 - 6 (Sunday is 0, Monday is 1, and so on)-
selectable-datesArray of selectable dates Array -
month-namesNames of months to display in table header Array ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
day-namesNames of days to display in table header Array ["Su", "M", "Tu", "W", "Th", "F", "S"]
first-day-of-weekFirst day of week to display in table header Number 0 - 6 (Sunday is 0, Monday is 1, and so on)0
mobile-nativeEnable native datepicker on mobile Boolean true, falsetrue
positionOptional, position of the datepicker relative to the input String is-top-right, is-top-left, is-bottom-leftBottom right
open-on-focusOpen datepicker on input focus Boolean false
typeType of picker String month-
years-rangeYears range relative to selected year Array -[-100, 3]
nearby-month-daysShow/Hide nearby month days (prev and next month) Boolean -true
nearby-selectable-month-daysWhen nearby-month-days, it allows to select/unselect nearby month days Boolean -false
show-week-numberDisplay week number Boolean -false
rules-for-first-weekChoose the rule to determinate the first week of Year, 4 for ISO or 1 for other Number -4
rangeFlag to allow choosing a range of date Boolean false
multipleFlag to allow choosing multiple dates Boolean false
focusableDatepicker container can be focused Boolean true
Any native attribute

# Variables

You can use these variables to customize this component.

Name
Default
$datepicker-background-color$dropdown-content-background-color
$datepicker-radius$dropdown-content-radius
$datepicker-shadow$dropdown-content-shadow
$datepicker-header-color$grey
$datepicker-today-bordersolid 1px rgba($primary, 0.5)
$datepicker-item-color$grey-dark
$datepicker-item-disabled-color$grey-light
$datepicker-item-hover-color$black
$datepicker-item-hover-background-color$background
$datepicker-item-selected-color$primary-invert
$datepicker-item-selected-background-color$primary

This page is open source. Noticed a typo or something's unclear?

Improve this page on GitHub