Skip to content

Commit

Permalink
feat(Select): ✨ 优化默认排序方法的表现,优化全等项的查询
Browse files Browse the repository at this point in the history
  • Loading branch information
Cat1007 committed Jan 21, 2025
1 parent 4ab00d1 commit 82d4ba8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/select/hooks/useSelectOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const useSelectOptions = (props: TdSelectProps, keys: Ref<KeysType>, inpu
return option.label?.toLowerCase?.().indexOf(`${inputValue.value}`.toLowerCase()) > -1;
};

const res: SelectOption[] = [];
let res: SelectOption[] = [];

options.value.forEach((option) => {
if ((option as SelectOptionGroup).children) {
Expand All @@ -131,6 +131,15 @@ export const useSelectOptions = (props: TdSelectProps, keys: Ref<KeysType>, inpu
}
});

if (!isFunction(props.filter)) {
// 使用默认 filter,增加表现,调整全等项到首尾,避免全等项位于最后
// inputValue: ab
// options abcde, abcd, abc, ab
const exactMatch = res.filter((item) => item.label === inputValue.value);
const fuzzyMatch = res.filter((item) => item.label !== inputValue.value);
res = exactMatch.concat(fuzzyMatch);
}

return res;
});

Expand Down

0 comments on commit 82d4ba8

Please sign in to comment.