feat: inputTag 支持边输入边搜索 Close: #1124 (#8533)

This commit is contained in:
liaoxuezhi 2023-10-30 18:46:56 +08:00 committed by GitHub
parent 320afe0148
commit d953a15134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@ import {isMobile} from 'amis-core';
import {FormOptionsSchema} from '../../Schema';
import {supportStatic} from './StaticHoc';
import {TooltipWrapperSchema} from '../TooltipWrapper';
import {matchSorter} from 'match-sorter';
/**
* Tag
@ -516,7 +517,7 @@ export default class TagControl extends React.PureComponent<
this.addItem2(option);
return;
}
if (this.isReachMax() || this.state.inputValue || !option) {
if (this.isReachMax() || !option) {
return;
}
@ -573,16 +574,22 @@ export default class TagControl extends React.PureComponent<
loadingConfig,
valueField,
env,
mobileUI
mobileUI,
labelField
} = this.props;
const term = this.state.inputValue;
const finnalOptions = Array.isArray(options)
? filterTree(
options,
item =>
(Array.isArray(item.children) && !!item.children.length) ||
(item[valueField || 'value'] !== undefined &&
(mobileUI || !~selectedOptions.indexOf(item))),
(item: Option, key: number, level: number, paths: Array<Option>) =>
item[valueField || 'value'] !== undefined &&
(mobileUI || !~selectedOptions.indexOf(item)) &&
(matchSorter([item].concat(paths), term, {
keys: [labelField || 'label', valueField || 'value'],
threshold: matchSorter.rankings.CONTAINS
}).length ||
(Array.isArray(item.children) && !!item.children.length)),
0,
true
)