mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
refactor(utils): improve escapeStringRegexp (#6013)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { inject, computed, getCurrentInstance, watch, toRaw, unref } from 'vue'
|
||||
import { get } from 'lodash-unified'
|
||||
import { escapeRegexpString } from '@element-plus/utils'
|
||||
import { escapeStringRegexp } from '@element-plus/utils'
|
||||
import { selectKey, selectGroupKey } from './token'
|
||||
|
||||
import type { Ref } from 'vue'
|
||||
@@ -120,7 +120,7 @@ export function useOption(props, states) {
|
||||
watch(queryChange, (changes: Ref<QueryChangeCtx>) => {
|
||||
const { query } = unref(changes)
|
||||
|
||||
const regexp = new RegExp(escapeRegexpString(query), 'i')
|
||||
const regexp = new RegExp(escapeStringRegexp(query), 'i')
|
||||
states.visible = regexp.test(currentLabel.value) || props.created
|
||||
if (!states.visible) {
|
||||
select.filteredOptionsCount--
|
||||
|
||||
@@ -5,5 +5,8 @@ export {
|
||||
hyphenate as kebabCase, // alias
|
||||
} from '@vue/shared'
|
||||
|
||||
export const escapeRegexpString = (value = '') =>
|
||||
String(value).replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
|
||||
/**
|
||||
* fork from {@link https://github.com/sindresorhus/escape-string-regexp}
|
||||
*/
|
||||
export const escapeStringRegexp = (string = '') =>
|
||||
string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d')
|
||||
|
||||
Reference in New Issue
Block a user