Skip to content

Commit

Permalink
fix: 过滤功能不能正常运转
Browse files Browse the repository at this point in the history
  • Loading branch information
yt0379 committed Sep 12, 2020
1 parent 007c402 commit a108c89
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
6 changes: 3 additions & 3 deletions packages/option-group/OptionGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default {
const { ctx } = getCurrentInstance()
watch(disabled, (val) => {
broadcast('ElOption', 'handleGroupDisabled', val)
broadcast('handleGroupDisabled', val)
})
function queryChange() {
Expand All @@ -52,12 +52,12 @@ export default {
}
onBeforeMount(() => {
on('queryChange', queryChange)
on('optionGroup.queryChange', queryChange)
})
onMounted(() => {
if (unref(disabled)) {
broadcast('ElOption', 'handleGroupDisabled', unref(disabled))
broadcast('handleGroupDisabled', unref(disabled))
}
})
Expand Down
8 changes: 4 additions & 4 deletions packages/option/Option.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,21 @@ export default {
function selectOptionClick() {
if (disabled.value !== true && data.groupDisabled !== true) {
dispatch('ElSelect', 'handleOptionClick', this, true)
dispatch('handleOptionClick', { option: this, byClick: true })
}
}
function queryChange(query) {
data.visible =
new RegExp(escapeRegexpString(query), 'i').test(currentLabel) ||
new RegExp(escapeRegexpString(query), 'i').test(unref(currentLabel)) ||
created.value
if (!data.visible) {
select.filteredOptionsCount--
}
}
watch(currentLabel, () => {
if (!created.value && !select.remote) dispatch('ElSelect', 'setSelected')
if (!created.value && !select.remote) dispatch('setSelected')
})
watch(value, (val, oldVal) => {
const { remote, valueKey } = select
Expand All @@ -161,7 +161,7 @@ export default {
) {
return
}
dispatch('ElSelect', 'setSelected')
dispatch('setSelected')
}
})
onBeforeMount(() => {
Expand Down
33 changes: 19 additions & 14 deletions packages/select/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
:tabindex="multiple && filterable ? '-1' : null"
@focus="handleFocus"
@blur="handleBlur"
@keyup.native="debouncedOnInputChange"
@keyup="debouncedOnInputChange"
@keydown.native.down.stop.prevent="navigateOptions('next')"
@keydown.native.up.stop.prevent="navigateOptions('prev')"
@keydown.native.enter.prevent="selectOption"
Expand Down Expand Up @@ -372,7 +372,6 @@ export default {
'clear',
'visible-change',
'remove-tag',
'handleOptionClick',
'setSelected'
],
Expand Down Expand Up @@ -440,13 +439,13 @@ export default {
this.inputLength = 20
}
if (!valueEquals(val, oldVal)) {
this.dispatch('ElFormItem', 'el.form.change', val)
this.dispatch('el.form.change', val)
}
},
visible(val) {
if (!val) {
this.broadcast('ElSelectDropdown', 'destroyPopper')
this.broadcast('destroyPopper')
if (this.$refs.input) {
this.$refs.input.blur()
}
Expand Down Expand Up @@ -485,16 +484,16 @@ export default {
}
}
} else {
this.broadcast('ElSelectDropdown', 'updatePopper')
this.broadcast('updatePopper')
if (this.filterable) {
this.query = this.remote ? '' : this.selectedLabel
this.handleQueryChange(this.query)
if (this.multiple) {
this.$refs.input.focus()
} else {
if (!this.remote) {
this.broadcast('ElOption', 'queryChange', '')
this.broadcast('ElOptionGroup', 'queryChange')
this.broadcast('queryChange', '')
this.broadcast('optionGroup.queryChange')
}
if (this.selectedLabel) {
Expand All @@ -510,7 +509,7 @@ export default {
options() {
if (this.$isServer) return
this.$nextTick(() => {
this.broadcast('ElSelectDropdown', 'updatePopper')
this.broadcast('updatePopper')
})
if (this.multiple) {
this.resetInputHeight()
Expand Down Expand Up @@ -552,7 +551,9 @@ export default {
}
this.previousQuery = val
this.$nextTick(() => {
if (this.visible) this.broadcast('ElSelectDropdown', 'updatePopper')
if (this.visible) {
this.broadcast('updatePopper')
}
})
this.hoverIndex = -1
if (this.multiple && this.filterable) {
Expand All @@ -568,11 +569,11 @@ export default {
this.remoteMethod(val)
} else if (typeof this.filterMethod === 'function') {
this.filterMethod(val)
this.broadcast('ElOptionGroup', 'queryChange')
this.broadcast('optionGroup.queryChange')
} else {
this.filteredOptionsCount = this.optionsCount
this.broadcast('ElOption', 'queryChange', val)
this.broadcast('ElOptionGroup', 'queryChange')
this.broadcast('queryChange', val)
this.broadcast('optionGroup.queryChange')
}
if (
this.defaultFirstOption &&
Expand Down Expand Up @@ -765,7 +766,7 @@ export default {
sizeInMap
) + 'px'
if (this.visible && this.emptyText !== false) {
this.broadcast('ElSelectDropdown', 'updatePopper')
this.broadcast('updatePopper')
}
})
},
Expand All @@ -787,7 +788,7 @@ export default {
}, 300)
},
handleOptionSelect(option, byClick) {
handleOptionSelect({ option, byClick }) {
if (this.multiple) {
const value = (this.modelValue || []).slice()
const optionIndex = this.getValueIndex(value, option.value)
Expand Down Expand Up @@ -958,6 +959,10 @@ export default {
} else {
return getValueByPath(item.value, this.valueKey)
}
},
search() {
console.log('aaaaa')
}
},
Expand Down
6 changes: 4 additions & 2 deletions packages/select/SelectDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ export default {
setup(props, ctx) {
const elSelect = inject('select')
const { referenceElm, popperElm } = usePopperElm(elSelect)
const popper = usePopper(referenceElm, props, ctx)
const popper = usePopper(referenceElm, popperElm, props, ctx)
usePopperUpdate(() => {
if (elSelect.visible) popper.updatePopper()
if (elSelect.visible) {
popper.updatePopper()
}
}, popper.destroyPopper)
const popperClass = computed(() => {
Expand Down

0 comments on commit a108c89

Please sign in to comment.