fix: search field should be searched based on the translated text (#5572)

This commit is contained in:
Katherine 2024-11-03 19:42:55 +08:00 committed by GitHub
parent 17582e9351
commit fdf8aa6f44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,6 +11,7 @@ import { uid } from '@formily/shared';
import { Divider, Empty, Input, MenuProps } from 'antd'; import { Divider, Empty, Input, MenuProps } from 'antd';
import React, { useEffect, useMemo, useState, useRef } from 'react'; import React, { useEffect, useMemo, useState, useRef } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useCompile } from '../../../';
function getPrefixAndCompare(a, b) { function getPrefixAndCompare(a, b) {
const prefixA = a.replace(/-displayCollectionFields$/, ''); const prefixA = a.replace(/-displayCollectionFields$/, '');
@ -100,6 +101,7 @@ export const useMenuSearch = (props: { children: any[]; showType?: boolean; hide
const { children, showType, hideSearch, name } = props; const { children, showType, hideSearch, name } = props;
const items = children?.concat?.() || []; const items = children?.concat?.() || [];
const [searchValue, setSearchValue] = useState(null); const [searchValue, setSearchValue] = useState(null);
const compile = useCompile();
// 处理搜索逻辑 // 处理搜索逻辑
const limitedSearchedItems = useMemo(() => { const limitedSearchedItems = useMemo(() => {
@ -107,13 +109,14 @@ export const useMenuSearch = (props: { children: any[]; showType?: boolean; hide
return items; return items;
} }
const lowerSearchValue = searchValue.toLocaleLowerCase(); const lowerSearchValue = searchValue.toLocaleLowerCase();
return items.filter( return items.filter((item) => {
(item) => return (
(item.title || item.label) && (item.title || item.label) &&
String(item.title || item.label) String(compile(item.title || item.label))
.toLocaleLowerCase() .toLocaleLowerCase()
.includes(lowerSearchValue), .includes(lowerSearchValue)
); );
});
}, [searchValue, items]); }, [searchValue, items]);
// 最终结果项 // 最终结果项