fix: escape regex special character

This commit is contained in:
Aslam H
2024-09-06 23:04:54 +07:00
parent ab74020149
commit 26386be50f
2 changed files with 46 additions and 45 deletions

View File

@@ -4,7 +4,7 @@ import React, { useState, useRef, useCallback, useMemo } from "react"
import { Command, CommandGroup, CommandItem, CommandList } from "@/components/ui/command"
import { Command as CommandPrimitive } from "cmdk"
import { motion, AnimatePresence } from "framer-motion"
import { cn } from "@/lib/utils"
import { cn, searchSafeRegExp } from "@/lib/utils"
interface GraphNode {
name: string
@@ -27,7 +27,8 @@ export function Autocomplete({ topics = [], onSelect, onInputChange }: Autocompl
if (!inputValue) {
return topics.slice(0, 5)
}
const regex = new RegExp(inputValue.split("").join(".*"), "i")
const regex = searchSafeRegExp(inputValue)
return topics.filter(
topic =>
regex.test(topic.name) ||