Skip to content

Commit 18e3a83

Browse files
committed
Add vue-clickaway to handle outside clicks and replace the overlay
1 parent 7f5f047 commit 18e3a83

6 files changed

+25
-16
lines changed

dist/vue-rangedate-picker.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-rangedate-picker.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"node": ">= 6.0"
9696
},
9797
"dependencies": {
98-
"fecha": "^2.3.2"
98+
"fecha": "^2.3.2",
99+
"vue-clickaway": "^2.2.2"
99100
}
100101
}

src/RangedatePicker.vue

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="calendar-root">
2+
<div class="calendar-root" v-on-clickaway="hideCalendar">
33
<div class="input-date" @click="toggleCalendar()"> {{getDateString(dateRange.start)}} - {{getDateString(dateRange.end)}}</div>
44
<div class="calendar" :class="{'calendar-mobile ': isCompact, 'calendar-right-to-left': isRighttoLeft}" v-if="isOpen">
55
<div class="calendar-head" v-if="!isCompact">
@@ -57,7 +57,6 @@
5757
</div>
5858

5959
</div>
60-
<div class='overlay' @click="toggleCalendar()" v-if="isOpen"></div>
6160
</div>
6261
</template>
6362

@@ -282,12 +281,4 @@ li.calendar_days_in-range {
282281
.cancel-button-hidden {
283282
display: none;
284283
}
285-
286-
.overlay {
287-
bottom: 0;
288-
left: 0;
289-
position: fixed;
290-
right: 0;
291-
top: 0;
292-
}
293284
</style>

src/js/rangedate-picker.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fecha from 'fecha'
2+
import { mixin as clickaway } from 'vue-clickaway'
23

34
const defaultConfig = {}
45
const defaultI18n = 'ID'
@@ -120,6 +121,7 @@ const defaultPresets = function (i18n = defaultI18n) {
120121
}
121122

122123
export default {
124+
mixins: [clickaway],
123125
name: 'vue-rangedate-picker',
124126
props: {
125127
configs: {
@@ -267,6 +269,15 @@ export default {
267269
}
268270
},
269271
methods: {
272+
hideCalendar: function () {
273+
if (this.isCompact) {
274+
this.showMonth = false
275+
return
276+
}
277+
this.showMonth = false
278+
this.isOpen = false
279+
return
280+
},
270281
toggleCalendar: function () {
271282
if (this.isCompact) {
272283
this.showMonth = !this.showMonth

0 commit comments

Comments
 (0)