Skip to content

Commit

Permalink
fix: when select time picker option close popup (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 committed Sep 28, 2018
1 parent 2444331 commit 12907ad
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
:value="value"
:disabled-time="isDisabledTime"
:time-type="timeType"
@select="selectTime" />
@select="selectTime"
@pick="pickTime" />
</div>
</div>
</template>
Expand Down Expand Up @@ -323,7 +324,10 @@ export default {
this.showPanelDate()
},
selectTime (time) {
this.$emit('select-time', time)
this.$emit('select-time', time, false)
},
pickTime (time) {
this.$emit('select-time', time, true)
},
changeCalendarYear (year) {
this.now = new Date(year, this.calendarMonth)
Expand Down
4 changes: 2 additions & 2 deletions src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ export default {
this.updateDate()
}
},
selectTime (time) {
selectTime (time, close) {
this.currentValue = time
this.updateDate()
this.updateDate() && close && this.closePopup()
},
selectStartTime (time) {
this.selectStartDate(time)
Expand Down
8 changes: 7 additions & 1 deletion src/panel/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export default {
}
this.$emit('select', new Date(time))
},
pickTime (time) {
if (typeof this.disabledTime === 'function' && this.disabledTime(time)) {
return
}
this.$emit('pick', new Date(time))
},
getTimeSelectOptions () {
const result = []
const options = this.timePickerOptions
Expand Down Expand Up @@ -96,7 +102,7 @@ export default {
'actived': pickHours === this.currentHours && pickMinutes === this.currentMinutes,
'disabled': disabledTime && disabledTime(time)
}}
onClick={this.selectTime.bind(this, time)}>{picker.label}</li>
onClick={this.pickTime.bind(this, time)}>{picker.label}</li>
)
})
return (
Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ describe('time-panel', () => {
cells.at(0).trigger('click')
const emitted = wrapper.emitted()
expect(emitted).toEqual({
select: [[new Date(2018, 5, 5, 1)]]
pick: [[new Date(2018, 5, 5, 1)]]
})
})
})

0 comments on commit 12907ad

Please sign in to comment.