mirror of
https://github.com/teableio/teable.git
synced 2026-03-23 00:04:56 +08:00
Merge 650e8ba266c1d66f97d231c1c030838d6b5e8b14 into 4dac92aa13c45d4c81e80068d39cab61280fca3a
This commit is contained in:
commit
01bc4bb245
@ -58,7 +58,28 @@ const SelectEditorMainBase: ForwardRefRenderFunction<
|
||||
const filteredOptions = useMemo(() => {
|
||||
if (!searchValue) return options;
|
||||
|
||||
return options.filter((v) => v.label.toLowerCase().includes(searchValue.toLowerCase()));
|
||||
const searchLower = searchValue.toLowerCase();
|
||||
const filtered = options.filter((v) => v.label.toLowerCase().includes(searchLower));
|
||||
|
||||
// Sort to prioritize exact matches and prefix matches
|
||||
return filtered.sort((a, b) => {
|
||||
const aLabelLower = a.label.toLowerCase();
|
||||
const bLabelLower = b.label.toLowerCase();
|
||||
|
||||
// Check for exact matches first
|
||||
if (aLabelLower === searchLower && bLabelLower !== searchLower) return -1;
|
||||
if (bLabelLower === searchLower && aLabelLower !== searchLower) return 1;
|
||||
|
||||
// Check for prefix matches
|
||||
const aStartsWith = aLabelLower.startsWith(searchLower);
|
||||
const bStartsWith = bLabelLower.startsWith(searchLower);
|
||||
|
||||
if (aStartsWith && !bStartsWith) return -1;
|
||||
if (bStartsWith && !aStartsWith) return 1;
|
||||
|
||||
// If both start with search or neither does, maintain original order
|
||||
return 0;
|
||||
});
|
||||
}, [options, searchValue]);
|
||||
|
||||
const onSelect = (val: string) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user