mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-27 03:01:14 +08:00
fix(select): hoverIndex has incorrect when popover is turned on again (#2469)
This commit is contained in:
parent
f6b17cb79a
commit
c1770d8877
@ -4,6 +4,7 @@ import { EVENT_CODE } from '@element-plus/utils/aria'
|
||||
import Select from '../src/select.vue'
|
||||
import Group from '../src/option-group.vue'
|
||||
import Option from '../src/option.vue'
|
||||
import { sleep } from '@element-plus/test-utils'
|
||||
|
||||
jest.useFakeTimers()
|
||||
|
||||
@ -313,11 +314,20 @@ describe('Select', () => {
|
||||
vm.navigateOptions('next')
|
||||
}
|
||||
vm.navigateOptions('prev')
|
||||
vm.navigateOptions('prev')
|
||||
vm.navigateOptions('prev')
|
||||
await vm.$nextTick()
|
||||
expect(vm.hoverIndex).toBe(0)
|
||||
expect(vm.hoverIndex).toBe(3)
|
||||
vm.selectOption()
|
||||
await vm.$nextTick()
|
||||
expect((wrapper.vm as any).value).toBe('选项1')
|
||||
expect((wrapper.vm as any).value).toBe('选项4')
|
||||
vm.toggleMenu()
|
||||
const timer = sleep(300)
|
||||
jest.runAllTimers()
|
||||
await timer
|
||||
vm.toggleMenu()
|
||||
await vm.$nextTick
|
||||
expect(vm.hoverIndex).toBe(3)
|
||||
})
|
||||
|
||||
test('clearable', async () => {
|
||||
|
@ -408,11 +408,18 @@ export const useSelect = (props, states: States, ctx) => {
|
||||
|
||||
const resetHoverIndex = () => {
|
||||
setTimeout(() => {
|
||||
const valueKey = props.valueKey
|
||||
if (!props.multiple) {
|
||||
states.hoverIndex = optionsArray.value.indexOf(states.selected)
|
||||
states.hoverIndex = optionsArray.value.findIndex(item => {
|
||||
return getValueByPath(item, valueKey) === getValueByPath(states.selected, valueKey)
|
||||
})
|
||||
} else {
|
||||
if (states.selected.length > 0) {
|
||||
states.hoverIndex = Math.min.apply(null, states.selected.map(item => optionsArray.value.indexOf(item)))
|
||||
states.hoverIndex = Math.min.apply(null, states.selected.map(selected => {
|
||||
return optionsArray.value.findIndex(item => {
|
||||
return getValueByPath(item, valueKey) === getValueByPath(selected, valueKey)
|
||||
})
|
||||
}))
|
||||
} else {
|
||||
states.hoverIndex = -1
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user