Skip to content

Commit 9aea190

Browse files
authored
added short delay before adding clickOutside listener
as described in charliekassel#377 it isn't currently possible to open the calendar programatically because the code immediately closes any calendar that is opened from a button that's outside the Datepicker component. Adding this short delay resolves the problem also added it as a wrapper function to prevent duplicate code
1 parent f33040f commit 9aea190

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/components/Datepicker.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,26 +386,27 @@ export default {
386386
387387
this.close()
388388
this.showDayView = true
389-
if (!this.isInline) {
390-
document.addEventListener('click', this.clickOutside, false)
391-
}
389+
this.addOutsideClickListener()
392390
},
393391
showMonthCalendar () {
394392
if (!this.allowedToShowView('month')) return false
395393
396394
this.close()
397395
this.showMonthView = true
398-
if (!this.isInline) {
399-
document.addEventListener('click', this.clickOutside, false)
400-
}
396+
this.addOutsideClickListener()
401397
},
402398
showYearCalendar () {
403399
if (!this.allowedToShowView('year')) return false
404400
405401
this.close()
406402
this.showYearView = true
403+
this.addOutsideClickListener()
404+
},
405+
addOutsideClickListener () {
407406
if (!this.isInline) {
408-
document.addEventListener('click', this.clickOutside, false)
407+
setTimeout(() => {
408+
document.addEventListener('click', this.clickOutside, false)
409+
}, 100)
409410
}
410411
},
411412
setDate (timestamp) {

0 commit comments

Comments
 (0)