mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-12 10:45:10 +08:00
fix: date-time picker sameday select time bug (#2747)
This commit is contained in:
parent
88a327fa4f
commit
90d901af3e
@ -499,4 +499,61 @@ describe('Datetimerange', () => {
|
||||
.map(node => Number(node.textContent))
|
||||
expect(disabledHours2).toStrictEqual(disabledHoursRightArr)
|
||||
})
|
||||
|
||||
it('select same date, different time', async () => {
|
||||
const leftSelect = ['10', '59', '59']
|
||||
const wrapper = _mount(`<el-date-picker
|
||||
v-model="value"
|
||||
type="datetimerange"
|
||||
/>`, () => ({
|
||||
value: '',
|
||||
}))
|
||||
const input = wrapper.find('input')
|
||||
input.trigger('blur')
|
||||
input.trigger('focus')
|
||||
await nextTick()
|
||||
const pickers = document.querySelectorAll('.el-date-range-picker__content')
|
||||
const leftCell = pickers[0].querySelector('td.available')
|
||||
triggerEvent(leftCell, 'mousemove', true)
|
||||
triggerEvent(leftCell, 'click', true)
|
||||
await nextTick()
|
||||
triggerEvent(leftCell, 'mousemove', true)
|
||||
triggerEvent(leftCell, 'click', true)
|
||||
await nextTick()
|
||||
const leftTimeInput = document.querySelectorAll('.el-date-range-picker__editors-wrap input')[1] as HTMLInputElement
|
||||
leftTimeInput.blur()
|
||||
leftTimeInput.focus()
|
||||
await nextTick()
|
||||
const leftList = document.querySelectorAll('.el-time-spinner__list')
|
||||
triggerEvent(leftList[0].children[+leftSelect[0]], 'click', true)
|
||||
await nextTick()
|
||||
triggerEvent(leftList[1].children[+leftSelect[1]], 'click', true)
|
||||
await nextTick()
|
||||
triggerEvent(leftList[2].children[+leftSelect[2]], 'click', true)
|
||||
await nextTick();
|
||||
(document.querySelector('.el-time-panel__btn.confirm') as HTMLElement).click()
|
||||
await nextTick()
|
||||
const rightTimeInput = document.querySelectorAll('.el-date-range-picker__editors-wrap input')[3] as HTMLInputElement
|
||||
rightTimeInput.blur()
|
||||
rightTimeInput.focus()
|
||||
await nextTick()
|
||||
const rightList = document.querySelectorAll('.is-right .el-time-spinner__list')
|
||||
// auto set left time to right time
|
||||
expect(rightList[0].querySelector('.el-time-spinner__item.active').innerHTML).toBe(leftSelect[0])
|
||||
expect(rightList[1].querySelector('.el-time-spinner__item.active').innerHTML).toBe(leftSelect[1])
|
||||
expect(rightList[2].querySelector('.el-time-spinner__item.active').innerHTML).toBe(leftSelect[2])
|
||||
triggerEvent(rightList[0].children[12], 'click', true)
|
||||
await nextTick()
|
||||
triggerEvent(rightList[1].children[12], 'click', true)
|
||||
await nextTick()
|
||||
triggerEvent(rightList[2].children[12], 'click', true)
|
||||
await nextTick();
|
||||
(document.querySelector('.is-right .el-time-panel__btn.confirm') as HTMLElement).click()
|
||||
await nextTick();
|
||||
(document.querySelector('.el-picker-panel__footer .el-button--default') as HTMLElement).click()
|
||||
await nextTick()
|
||||
const vm = wrapper.vm as any
|
||||
expect(vm.value.map(_ => dayjs(_).format('HH:mm:ss')))
|
||||
.toStrictEqual(['10:59:59', '12:12:12'])
|
||||
})
|
||||
})
|
||||
|
@ -527,8 +527,7 @@ export default defineComponent({
|
||||
|
||||
if (!maxDate.value || maxDate.value.isBefore(minDate.value)) {
|
||||
maxDate.value = minDate.value
|
||||
rightDate.value = maxDate.value
|
||||
rightDate.value = rightDate.value.add(1, 'month')
|
||||
rightDate.value = value
|
||||
}
|
||||
}
|
||||
|
||||
@ -545,7 +544,6 @@ export default defineComponent({
|
||||
|
||||
if (maxDate.value && maxDate.value.isBefore(minDate.value)) {
|
||||
minDate.value = maxDate.value
|
||||
leftDate.value = minDate.value
|
||||
}
|
||||
}
|
||||
|
||||
@ -616,6 +614,12 @@ export default defineComponent({
|
||||
: maxDate.value
|
||||
} else {
|
||||
rightDate.value = leftDate.value.add(1, 'month')
|
||||
if (maxDate.value) {
|
||||
rightDate.value = rightDate.value
|
||||
.hour(maxDate.value.hour())
|
||||
.minute(maxDate.value.minute())
|
||||
.second(maxDate.value.second())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const defaultArr = getDefaultValue()
|
||||
|
Loading…
Reference in New Issue
Block a user