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

fix(select): checkAll will check all filtered data of reserveKeyword #4898

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/select/hooks/useSelectOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const useSelectOptions = (props: TdSelectProps, keys: Ref<KeysType>, inpu
if (isFunction(props.filter)) {
return props.filter(`${inputValue.value}`, option);
}

if ((option as TdOptionProps)?.checkAll === true) return true;
return option.label?.toLowerCase?.().indexOf(`${inputValue.value}`.toLowerCase()) > -1;
};

Expand Down
23 changes: 18 additions & 5 deletions src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,24 @@ export default defineComponent({
max: props.max,
});

/**
* 获取过滤后可以全选的选项
* @returns 可选选项的列表的value
* @todo 如果未来setInnerValue 的第一个参数更改为对象类型,需要修改
*/
const getFilteredOptions = () =>
optionalList.value
.filter((option) => {
if (isFunction(props.filter)) {
return props.filter(`${innerInputValue.value}`, option);
}
return option.label?.toLowerCase()?.includes(`${innerInputValue.value}`.toLowerCase());
})
.map((option) => option.value);

const onCheckAllChange = (checked: boolean) => {
if (!props.multiple) return;
const value = checked ? optionalList.value.map((option) => option.value) : [];
const value = checked ? getFilteredOptions() : [];
setInnerValue(value, { selectedOptions: getSelectedOptions(value), trigger: checked ? 'check' : 'clear' });
};

Expand All @@ -223,10 +238,8 @@ export default defineComponent({
return n.length;
});

// 全选
const isCheckAll = computed<boolean>(() => {
return intersectionLen.value === optionalList.value.length;
});
// 是否全选
const isCheckAll = computed<boolean>(() => intersectionLen.value === getFilteredOptions().length);

// 半选
const indeterminate = computed<boolean>(() => !isCheckAll.value && intersectionLen.value !== 0);
Expand Down
Loading