Skip to content

Commit

Permalink
Add vue-clickaway to handle outside clicks and replace the overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
ellerynz committed Aug 30, 2018
1 parent 7f5f047 commit 18e3a83
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/vue-rangedate-picker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-rangedate-picker.min.js

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"node": ">= 6.0"
},
"dependencies": {
"fecha": "^2.3.2"
"fecha": "^2.3.2",
"vue-clickaway": "^2.2.2"
}
}
11 changes: 1 addition & 10 deletions src/RangedatePicker.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="calendar-root">
<div class="calendar-root" v-on-clickaway="hideCalendar">
<div class="input-date" @click="toggleCalendar()"> {{getDateString(dateRange.start)}} - {{getDateString(dateRange.end)}}</div>
<div class="calendar" :class="{'calendar-mobile ': isCompact, 'calendar-right-to-left': isRighttoLeft}" v-if="isOpen">
<div class="calendar-head" v-if="!isCompact">
Expand Down Expand Up @@ -57,7 +57,6 @@
</div>

</div>
<div class='overlay' @click="toggleCalendar()" v-if="isOpen"></div>
</div>
</template>

Expand Down Expand Up @@ -282,12 +281,4 @@ li.calendar_days_in-range {
.cancel-button-hidden {
display: none;
}
.overlay {
bottom: 0;
left: 0;
position: fixed;
right: 0;
top: 0;
}
</style>
11 changes: 11 additions & 0 deletions src/js/rangedate-picker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fecha from 'fecha'
import { mixin as clickaway } from 'vue-clickaway'

const defaultConfig = {}
const defaultI18n = 'ID'
Expand Down Expand Up @@ -120,6 +121,7 @@ const defaultPresets = function (i18n = defaultI18n) {
}

export default {
mixins: [clickaway],
name: 'vue-rangedate-picker',
props: {
configs: {
Expand Down Expand Up @@ -267,6 +269,15 @@ export default {
}
},
methods: {
hideCalendar: function () {
if (this.isCompact) {
this.showMonth = false
return
}
this.showMonth = false
this.isOpen = false
return
},
toggleCalendar: function () {
if (this.isCompact) {
this.showMonth = !this.showMonth
Expand Down

0 comments on commit 18e3a83

Please sign in to comment.