Commit aa27888a authored by Leopoldthecoder's avatar Leopoldthecoder Committed by cinwell.li

Select: fix an illegal filter regexp bug

parent fad0fd32
......@@ -3,7 +3,7 @@
@mouseenter="hoverItem"
@click.stop="selectOptionClick"
class="el-select-dropdown__item"
v-show="queryPassed"
v-show="visible"
:class="{ 'selected': itemSelected, 'is-disabled': disabled || groupDisabled, 'hover': parent.hoverIndex === index }">
<slot>
<span>{{ currentLabel }}</span>
......@@ -40,7 +40,7 @@
return {
index: -1,
groupDisabled: false,
queryPassed: true,
visible: true,
hitState: false
};
},
......@@ -97,8 +97,10 @@
},
queryChange(query) {
this.queryPassed = new RegExp(query, 'i').test(this.currentLabel);
if (!this.queryPassed) {
// query 里如果有正则中的特殊字符,需要先将这些字符转义
let parsedQuery = query.replace(/(\^|\(|\)|\[|\]|\$|\*|\+|\.|\?|\\|\{|\}|\|)/g, '\\$1');
this.visible = new RegExp(parsedQuery, 'i').test(this.currentLabel);
if (!this.visible) {
this.parent.filteredOptionsCount--;
}
},
......
......@@ -444,7 +444,7 @@
this.resetScrollTop();
if (this.options[this.hoverIndex].disabled === true ||
this.options[this.hoverIndex].groupDisabled === true ||
!this.options[this.hoverIndex].queryPassed) {
!this.options[this.hoverIndex].visible) {
this.navigateOptions('next');
}
}
......@@ -456,7 +456,7 @@
this.resetScrollTop();
if (this.options[this.hoverIndex].disabled === true ||
this.options[this.hoverIndex].groupDisabled === true ||
!this.options[this.hoverIndex].queryPassed) {
!this.options[this.hoverIndex].visible) {
this.navigateOptions('prev');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment