Skip to content

Commit

Permalink
fix(Select): support checkAll option when using filterable API (#3295)
Browse files Browse the repository at this point in the history
* perf(select): 全选常驻

* perf(select): 选择器搜索时支持全选选项常驻

* chore(select): 支持搜索词保留
  • Loading branch information
zhengchengshi authored Sep 3, 2024
1 parent 4e539d8 commit 790b1e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/select/select-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default defineComponent({
if (isFunction(props.filter)) {
return props.filter(`${props.inputValue}`, option);
}
if ((option as TdOptionProps)?.checkAll === true) return true;
return option.label?.toLowerCase?.().indexOf(`${props.inputValue}`.toLowerCase()) > -1;
};

Expand Down
10 changes: 9 additions & 1 deletion src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import useVModel from '../hooks/useVModel';
import { useTNodeJSX } from '../hooks/tnode';
import { useConfig, usePrefixClass } from '../config-provider/useConfig';
import {
TdSelectProps, SelectValue, TdOptionProps, SelectValueChangeTrigger,
TdSelectProps, SelectValue, TdOptionProps, SelectValueChangeTrigger, SelectOption,
} from './type';
import props from './props';
import TLoading from '../loading';
Expand Down Expand Up @@ -309,14 +309,22 @@ export default defineComponent({

// 全选点击回调,t-option 的事件调用到这里处理
const handleCheckAllClick = (e: MouseEvent | KeyboardEvent) => {
const filterMethods = (option: SelectOption) => {
if (isFunction(props.filter)) {
return props.filter(`${tInputValue.value}`, option);
}
return option.label?.toLowerCase?.().indexOf(`${tInputValue.value}`.toLowerCase()) > -1;
};
setInnerValue(
isAllOptionsChecked.value
? []
: getAllSelectableOption(optionsList.value)
.filter(filterMethods)
.map((option) => option.value)
.slice(0, max.value || Infinity),
{ e, trigger: isAllOptionsChecked.value ? 'uncheck' : 'check' },
);
!reserveKeyword?.value && setTInputValue('');
};

const handleCreate = () => {
Expand Down

0 comments on commit 790b1e2

Please sign in to comment.