Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Select): ✨ 优化默认排序方法的表现,优化全等项的查询 #4945

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading