Skip to content

Commit 1d4762c

Browse files
authored
fix(select): checkAll will check all filtered data of reserveKeyword (#3440)
* perf(select): `checkAll` will check all to keep the filtered data of `reserveKeyword` * chore: remove unuse code
1 parent 47d555d commit 1d4762c

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/select/select.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import useVModel from '../hooks/useVModel';
1919
import { useTNodeJSX } from '../hooks/tnode';
2020
import { useConfig, usePrefixClass } from '../config-provider/useConfig';
2121
import {
22-
TdSelectProps, SelectValue, TdOptionProps, SelectValueChangeTrigger, SelectOption,
22+
TdSelectProps, SelectValue, TdOptionProps, SelectValueChangeTrigger,
2323
} from './type';
2424
import props from './props';
2525
import TLoading from '../loading';
@@ -246,9 +246,18 @@ export default defineComponent({
246246
const isReachMaxLimit = computed(
247247
() => multiple.value && max.value !== 0 && max.value <= (innerValue.value as SelectValue[]).length,
248248
);
249-
const isAllOptionsChecked = computed(
250-
() => getAllSelectableOption(optionsList.value).length === (innerValue.value as SelectValue[]).length,
251-
);
249+
250+
const getFilteredOptions = () => getAllSelectableOption(optionsList.value).filter((option) => {
251+
if (isFunction(props.filter)) {
252+
return props.filter(`${tInputValue.value}`, option);
253+
}
254+
return option.label?.toLowerCase()?.includes(`${tInputValue.value}`.toLowerCase());
255+
});
256+
257+
const isAllOptionsChecked = computed(() => {
258+
const filteredOptions = getFilteredOptions();
259+
return filteredOptions.length === (innerValue.value as SelectValue[]).length;
260+
});
252261

253262
const placeholderText = computed(
254263
() => ((!multiple.value
@@ -331,19 +340,9 @@ export default defineComponent({
331340

332341
// 全选点击回调,t-option 的事件调用到这里处理
333342
const handleCheckAllClick = (e: MouseEvent | KeyboardEvent) => {
334-
const filterMethods = (option: SelectOption) => {
335-
if (isFunction(props.filter)) {
336-
return props.filter(`${tInputValue.value}`, option);
337-
}
338-
return option.label?.toLowerCase?.().indexOf(`${tInputValue.value}`.toLowerCase()) > -1;
339-
};
343+
const filteredOptions = getFilteredOptions();
340344
setInnerValue(
341-
isAllOptionsChecked.value
342-
? []
343-
: getAllSelectableOption(optionsList.value)
344-
.filter(filterMethods)
345-
.map((option) => option.value)
346-
.slice(0, max.value || Infinity),
345+
isAllOptionsChecked.value ? [] : filteredOptions.map((option) => option.value).slice(0, max.value || Infinity),
347346
{ e, trigger: isAllOptionsChecked.value ? 'uncheck' : 'check' },
348347
);
349348
!reserveKeyword?.value && setTInputValue('', { e, trigger: 'change' });

0 commit comments

Comments
 (0)