mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-04 20:27:44 +08:00
fix(time-picker): model-value should sync when disable-attrs was updated (#2462)
This commit is contained in:
parent
1e44af0b91
commit
6305f7af80
@ -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)', () => {
|
||||
|
@ -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 = []
|
||||
|
Loading…
Reference in New Issue
Block a user