fix(date-picker): default-time does not work when type is datetime

fix #1915
This commit is contained in:
Map1en_ 2021-04-29 15:43:15 +08:00 committed by Herrington Darkholme
parent 6182fd3b96
commit 9dd3249f28
2 changed files with 28 additions and 1 deletions

View File

@ -264,6 +264,33 @@ describe('Datetime Picker', () => {
.map(node => Number(node.textContent))
expect(disabledMinutes.length).toBe(19)
})
it('defaultTime takes effect when the type is datetime', async () => {
const wrapper = _mount(`<el-date-picker
v-model="value"
type="datetime"
:default-time="defaultTime"
/>`, () => ({
value: '',
defaultTime: new Date(2000, 1, 1, 12, 24, 48),
}))
const input = wrapper.find('input')
input.trigger('blur')
input.trigger('focus')
await nextTick()
const someDateTd = document.querySelector('.el-picker-panel__content tr:nth-child(3) td:nth-child(4)')
const timeInput = document.querySelector('.el-date-picker__time-header > span:nth-child(2) input');
(someDateTd as HTMLElement).click();
(timeInput as HTMLElement).focus()
await nextTick()
expect((timeInput as HTMLInputElement).value).toBe('12:24:48')
// time spinner highlight is correct
const spinners = document.querySelectorAll('.el-time-spinner ul li.active') as any
expect(spinners[0].textContent).toBe('12')
expect(spinners[1].textContent).toBe('24')
expect(spinners[2].textContent).toBe('48')
})
})
describe('Datetimerange', () => {

View File

@ -215,11 +215,11 @@ export default defineComponent({
: true
}
const formatEmit = (emitDayjs: Dayjs) => {
if (showTime.value) return emitDayjs.millisecond(0)
if (defaultTime) {
const defaultTimeD = dayjs(defaultTime)
return defaultTimeD.year(emitDayjs.year()).month(emitDayjs.month()).date(emitDayjs.date())
}
if (showTime.value) return emitDayjs.millisecond(0)
return emitDayjs.startOf('day')
}
const emit = (value, ...args) => {