Skip to content

Commit

Permalink
add mounted hook in attempt to support Vue 2.x and default value for …
Browse files Browse the repository at this point in the history
…calendarHeight pre render
  • Loading branch information
Charlie Kassel committed Nov 3, 2016
1 parent 5e96361 commit 27e6ccf
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions src/Datepicker.vue
Expand Up @@ -213,7 +213,7 @@ export default {
return years
},
calendarStyle () {
let elSize = this.$el.getBoundingClientRect()
let elSize = this.$el ? this.$el.getBoundingClientRect() : 0
let heightNeeded = elSize.top + elSize.height + this.calendarHeight
let styles = {}
// if the calendar doesn't fit on the window without scrolling position it above the input
Expand Down Expand Up @@ -604,25 +604,38 @@ export default {
this.selectedDate = date
this.currDate = new Date(date.getFullYear(), date.getMonth(), 1).getTime()
this.formattedValue = DateUtils.formatDate(date, this.format, this.translation)
},
init () {
if (this.value) {
this.setValue(this.value)
}
if (this.isInline()) {
this.showDayCalendar()
}
this.$nextTick(() => {
this.calendarHeight = this.$el.querySelector('.calendar').getBoundingClientRect().height
})
document.addEventListener('click', (e) => {
if (this.$el && !this.$el.contains(e.target)) {
(this.isInline()) ? this.showDayCalendar() : this.close()
}
}, false)
}
},
/**
* Vue 1.x
*/
ready () {
if (this.value) {
this.setValue(this.value)
}
if (this.isInline()) {
this.showDayCalendar()
}
this.$nextTick(() => {
this.calendarHeight = this.$el.querySelector('.calendar').getBoundingClientRect().height
})
document.addEventListener('click', (e) => {
if (this.$el && !this.$el.contains(e.target)) {
(this.isInline()) ? this.showDayCalendar() : this.close()
}
}, false)
this.init()
},
/**
* Vue 2.x
*/
mounted () {
this.init()
}
}
</script>
Expand Down

0 comments on commit 27e6ccf

Please sign in to comment.