From 3514cfbd449bf7a8de4fe3f6b7db91c739591fce Mon Sep 17 00:00:00 2001 From: dongchengjie <37543964+dongchengjie@users.noreply.github.com> Date: Thu, 30 May 2024 10:45:24 +0800 Subject: [PATCH] fix: research when search box mode changes --- src/components/base/base-search-box.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/base/base-search-box.tsx b/src/components/base/base-search-box.tsx index bffb507..3a15458 100644 --- a/src/components/base/base-search-box.tsx +++ b/src/components/base/base-search-box.tsx @@ -1,6 +1,6 @@ -import { Box, SvgIcon, TextField, Theme, styled } from "@mui/material"; +import { Box, SvgIcon, TextField, styled } from "@mui/material"; import Tooltip from "@mui/material/Tooltip"; -import { ChangeEvent, useState } from "react"; +import { ChangeEvent, useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import matchCaseIcon from "@/assets/image/component/match_case.svg?react"; @@ -22,6 +22,7 @@ type SearchProps = { export const BaseSearchBox = styled((props: SearchProps) => { const { t } = useTranslation(); + const inputRef = useRef(null); const [matchCase, setMatchCase] = useState(true); const [matchWholeWord, setMatchWholeWord] = useState(false); const [useRegularExpression, setUseRegularExpression] = useState(false); @@ -36,6 +37,14 @@ export const BaseSearchBox = styled((props: SearchProps) => { inheritViewBox: true, }; + useEffect(() => { + if (!inputRef.current) return; + + onChange({ + target: inputRef.current, + } as ChangeEvent); + }, [matchCase, matchWholeWord, useRegularExpression]); + const onChange = (e: ChangeEvent) => { props.onSearch( (content) => doSearch([content], e.target?.value ?? "").length > 0, @@ -80,6 +89,7 @@ export const BaseSearchBox = styled((props: SearchProps) => { return (