fix(time-picker): model-value should sync when disable-attrs was updated (#2462)

This commit is contained in:
msidolphin 2021-07-13 09:25:04 +08:00 committed by GitHub
parent 1e44af0b91
commit 6305f7af80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -323,6 +323,39 @@ describe('TimePicker', () => {
const attr = popperEl.getAttribute('aria-hidden')
expect(attr).toEqual('true')
})
it('model value should sync when disabled-hours was updated', async () => {
const wrapper = _mount(`
<el-time-picker
v-model="value"
:disabled-hours="disabledHours"
value-format="YYYY-MM-DD HH:mm:ss"
/>
`, () => ({
value: '2000-01-01 00:00:00',
minHour: '8',
}), {
computed: {
disabledHours() {
return () => {
return Array(24)
.fill(null)
.map((_, i) => i)
.filter(h => h < parseInt(this.minHour, 10))
}
},
},
})
await nextTick()
const vm = wrapper.vm as any
expect(vm.value).toEqual('2000-01-01 08:00:00')
vm.minHour = '9'
await nextTick()
expect(vm.value).toEqual('2000-01-01 09:00:00')
vm.minHour = '8'
await nextTick()
expect(vm.value).toEqual('2000-01-01 09:00:00')
})
})
describe('TimePicker(range)', () => {

View File

@ -132,6 +132,7 @@ import {
provide,
} from 'vue'
import dayjs, { Dayjs } from 'dayjs'
import isEqual from 'lodash/isEqual'
import { ClickOutside } from '@element-plus/directives'
import ElInput from '@element-plus/input'
import ElPopper from '@element-plus/popper'
@ -302,7 +303,11 @@ export default defineComponent({
}
if (pickerOptions.value.getRangeAvailableTime) {
result = pickerOptions.value.getRangeAvailableTime(result)
const availableResult = pickerOptions.value.getRangeAvailableTime(result)
if (!isEqual(availableResult, result)) {
result = availableResult
emitInput(Array.isArray(result) ? result.map(_=> _.toDate()) : result.toDate())
}
}
if (Array.isArray(result) && result.some(_ => !_)) {
result = []