Select: fix an illegal filter regexp bug

pull/828/head
Leopoldthecoder 2016-11-04 16:47:11 +08:00 committed by cinwell.li
parent fad0fd320c
commit aa27888a58
2 changed files with 8 additions and 6 deletions

View File

@ -3,7 +3,7 @@
@mouseenter="hoverItem" @mouseenter="hoverItem"
@click.stop="selectOptionClick" @click.stop="selectOptionClick"
class="el-select-dropdown__item" class="el-select-dropdown__item"
v-show="queryPassed" v-show="visible"
:class="{ 'selected': itemSelected, 'is-disabled': disabled || groupDisabled, 'hover': parent.hoverIndex === index }"> :class="{ 'selected': itemSelected, 'is-disabled': disabled || groupDisabled, 'hover': parent.hoverIndex === index }">
<slot> <slot>
<span>{{ currentLabel }}</span> <span>{{ currentLabel }}</span>
@ -40,7 +40,7 @@
return { return {
index: -1, index: -1,
groupDisabled: false, groupDisabled: false,
queryPassed: true, visible: true,
hitState: false hitState: false
}; };
}, },
@ -97,8 +97,10 @@
}, },
queryChange(query) { queryChange(query) {
this.queryPassed = new RegExp(query, 'i').test(this.currentLabel); // query
if (!this.queryPassed) { let parsedQuery = query.replace(/(\^|\(|\)|\[|\]|\$|\*|\+|\.|\?|\\|\{|\}|\|)/g, '\\$1');
this.visible = new RegExp(parsedQuery, 'i').test(this.currentLabel);
if (!this.visible) {
this.parent.filteredOptionsCount--; this.parent.filteredOptionsCount--;
} }
}, },

View File

@ -444,7 +444,7 @@
this.resetScrollTop(); this.resetScrollTop();
if (this.options[this.hoverIndex].disabled === true || if (this.options[this.hoverIndex].disabled === true ||
this.options[this.hoverIndex].groupDisabled === true || this.options[this.hoverIndex].groupDisabled === true ||
!this.options[this.hoverIndex].queryPassed) { !this.options[this.hoverIndex].visible) {
this.navigateOptions('next'); this.navigateOptions('next');
} }
} }
@ -456,7 +456,7 @@
this.resetScrollTop(); this.resetScrollTop();
if (this.options[this.hoverIndex].disabled === true || if (this.options[this.hoverIndex].disabled === true ||
this.options[this.hoverIndex].groupDisabled === true || this.options[this.hoverIndex].groupDisabled === true ||
!this.options[this.hoverIndex].queryPassed) { !this.options[this.hoverIndex].visible) {
this.navigateOptions('prev'); this.navigateOptions('prev');
} }
} }