Skip to content

Commit

Permalink
fix: 键盘导航失效
Browse files Browse the repository at this point in the history
  • Loading branch information
yt0379 committed Sep 14, 2020
1 parent 1f5a552 commit c353916
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
14 changes: 7 additions & 7 deletions packages/option/Option.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default {
setup(props) {
const { on, dispatch } = useEmitter()
const select = inject('select')
const { ctx } = getCurrentInstance()
const { proxy } = getCurrentInstance()
const { value, label, disabled, created } = toRefs(props)
const data = reactive({
index: -1,
Expand Down Expand Up @@ -128,7 +128,7 @@ export default {
function hoverItem() {
if (!disabled.value && !data.groupDisabled) {
select.hoverIndex = select.options.indexOf(ctx)
select.hoverIndex = select.options.indexOf(proxy)
}
}
Expand Down Expand Up @@ -165,8 +165,8 @@ export default {
}
})
onBeforeMount(() => {
select.options.push(ctx)
select.cachedOptions.push(ctx)
select.options.push(proxy)
select.cachedOptions.push(proxy)
select.optionsCount++
select.filteredOptionsCount++
Expand All @@ -176,14 +176,14 @@ export default {
onBeforeUnmount(() => {
const { selected, multiple } = select
const selectedOptions = multiple ? selected : [selected]
const index = select.cachedOptions.indexOf(ctx)
const selectedIndex = selectedOptions.indexOf(ctx)
const index = select.cachedOptions.indexOf(proxy)
const selectedIndex = selectedOptions.indexOf(proxy)
// if option is not selected, remove it from cache
if (index > -1 && selectedIndex < 0) {
select.cachedOptions.splice(index, 1)
}
select.onOptionDestroy(select.options.indexOf(ctx))
select.onOptionDestroy(select.options.indexOf(proxy))
})
return {
Expand Down
22 changes: 8 additions & 14 deletions packages/select/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@
@focus="handleFocus"
@blur="handleBlur"
@keyup="debouncedOnInputChange"
@keydown.native.down.stop.prevent="navigateOptions('next')"
@keydown.native.up.stop.prevent="navigateOptions('prev')"
@keydown.native.enter.prevent="selectOption"
@keydown.native.esc.stop.prevent="visible = false"
@keydown.native.tab="visible = false"
@keydown.down.stop.prevent="navigateOptions('next')"
@keydown.up.stop.prevent="navigateOptions('prev')"
@keydown.enter.prevent="selectOption"
@keydown.esc.stop.prevent="visible = false"
@keydown.tab="visible = false"
@paste.native="debouncedOnInputChange"
>
<template v-slot:prefix v-if="$slots.prefix">
Expand Down Expand Up @@ -869,7 +869,9 @@ export default {
this.toggleMenu()
} else {
if (this.options[this.hoverIndex]) {
this.handleOptionSelect(this.options[this.hoverIndex])
this.handleOptionSelect({
option: this.options[this.hoverIndex]
})
}
}
},
Expand Down Expand Up @@ -959,10 +961,6 @@ export default {
} else {
return getValueByPath(item.value, this.valueKey)
}
},
search() {
console.log('aaaaa')
}
},
Expand All @@ -988,10 +986,6 @@ export default {
this.on('handleOptionClick', this.handleOptionSelect)
this.on('setSelected', this.setSelected)
},
updated() {
this.on('handleOptionClick', this.handleOptionSelect)
this.on('setSelected', this.setSelected)
},
mounted() {
if (
this.multiple &&
Expand Down

0 comments on commit c353916

Please sign in to comment.