fix(DateTimePicker): fix action when max-hour or max-minute is set smaller then current time(#5005) (#5006)

This commit is contained in:
tango5614 2019-11-14 19:09:19 +08:00 committed by neverland
parent 7aee4fb9a2
commit 4c9eb995d4
2 changed files with 19 additions and 3 deletions

View File

@ -74,9 +74,9 @@ export default createComponent({
}, },
updateInnerValue() { updateInnerValue() {
const indexes = this.$refs.picker.getIndexes(); const [hourIndex, minuteIndex] = this.$refs.picker.getIndexes();
const hour = this.originColumns[0].values[indexes[0]]; const hour = this.originColumns[0].values[hourIndex] || this.originColumns[0].values[0];
const minute = this.originColumns[1].values[indexes[1]]; const minute = this.originColumns[1].values[minuteIndex] || this.originColumns[1].values[0];
const value = `${hour}:${minute}`; const value = `${hour}:${minute}`;
this.innerValue = this.formatValue(value); this.innerValue = this.formatValue(value);

View File

@ -107,3 +107,19 @@ test('change min-minute and emit correct value', async () => {
wrapper.find('.van-picker__confirm').trigger('click'); wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[0][0]).toEqual('12:30'); expect(wrapper.emitted('confirm')[0][0]).toEqual('12:30');
}); });
test('set max-hour & max-minute smaller than current then emit correct value', async () => {
const wrapper = mount(TimePicker, {
propsData: {
value: '23:59',
}
});
await later();
wrapper.setProps({
maxHour: 2,
maxMinute: 2,
});
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[0][0]).toEqual('00:00');
});