Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
- apply date changes if user clicks apply or clicks outside of
Browse files Browse the repository at this point in the history
the datepicker
- notify parent component when datepicker closes
  • Loading branch information
pdvluca committed Mar 22, 2018
1 parent 4bef786 commit 8206c52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
9 changes: 4 additions & 5 deletions dev/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
:end-date="'2018-05-10'"
:months-to-show="2"
:start-open="false"
:require-apply="true"
@date-one-selected="val => { inputDateOne = val }"
@date-two-selected="val => { inputDateTwo = val }"
@dates-applied="datesApplied"
@closed="onClosed"
/>
</div>
</div>
Expand Down Expand Up @@ -99,9 +98,9 @@ export default {
}
return formattedDates
},
datesApplied(dateOne, dateTwo) {
var datesStr = this.formatDates(dateOne, dateTwo)
window.alert('Dates Selected: ' + datesStr)
onClosed() {
var datesStr = this.formatDates(this.inputDateOne, this.inputDateTwo)
console.log('Dates Selected: ' + datesStr)
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions src/components/AirbnbStyleDatepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
v-show="showDatepicker"
:class="wrapperClasses"
:style="showFullscreen ? undefined : wrapperStyles"
v-click-outside="closeDatepickerCancel"
v-click-outside="closeDatepicker"
>
<div class="mobile-header mobile-only" v-if="showFullscreen">
<div class="mobile-close" @click="closeDatepicker">
Expand Down Expand Up @@ -84,7 +84,7 @@
</div>
<div class="action-buttons" v-if="mode !== 'single'">
<button @click="closeDatepickerCancel">{{ texts.cancel }}</button>
<button @click="closeDatepickerApply" :style="{color: colors.selected}">{{ texts.apply }}</button>
<button @click="closeDatepicker" :style="{color: colors.selected}">{{ texts.apply }}</button>
</div>
</div>
</transition>
Expand Down Expand Up @@ -113,7 +113,6 @@ export default {
offsetX: { type: Number, default: 0 },
monthsToShow: { type: Number, default: 2 },
startOpen: { type: Boolean },
requireApply: { type: Boolean, default: false },
fullscreenMobile: { type: Boolean },
inline: { type: Boolean },
mobileHeader: { type: String, default: 'Select date' }
Expand Down Expand Up @@ -469,21 +468,18 @@ export default {
},
closeDatepickerCancel() {
if (this.showDatepicker) {
if (this.requireApply) {
this.selectedDate1 = this.initialDate1
this.selectedDate2 = this.initialDate2
}
this.selectedDate1 = this.initialDate1
this.selectedDate2 = this.initialDate2
this.closeDatepicker()
}
},
closeDatepickerApply() {
this.closeDatepicker()
this.$emit('dates-applied', this.selectedDate1, this.selectedDate2)
},
closeDatepicker() {
if (this.inline) {
return
}
if (this.showDatepicker) {
this.$nextTick(() => this.$emit('closed'))
}
this.showDatepicker = false
},
positionDatepicker() {
Expand Down

0 comments on commit 8206c52

Please sign in to comment.