diff --git a/packages/amis-ui/src/components/Select.tsx b/packages/amis-ui/src/components/Select.tsx index b51faa430..4a016baa6 100644 --- a/packages/amis-ui/src/components/Select.tsx +++ b/packages/amis-ui/src/components/Select.tsx @@ -16,7 +16,6 @@ import {PopOver} from 'amis-core'; import TooltipWrapper from './TooltipWrapper'; import Downshift, {ControllerStateAndHelpers} from 'downshift'; import {closeIcon, Icon} from './icons'; -// @ts-ignore import {matchSorter} from 'match-sorter'; import { noop, @@ -47,6 +46,15 @@ import type {TooltipObject} from '../components/TooltipWrapper'; export {Option, Options}; +export const defaultFilterOption = ( + options: Option[], + inputValue: string, + option: {keys: string[]}, + matchFn = matchSorter +): Option[] => matchFn(options, inputValue, option); + +export type FilterOption = typeof defaultFilterOption; + export interface OptionProps { className?: string; multi?: boolean; @@ -375,6 +383,11 @@ interface SelectProps * 收纳标签的Popover配置 */ overflowTagPopover?: TooltipObject; + + /** + * 检索函数 + */ + filterOption?: FilterOption; } interface SelectState { @@ -573,15 +586,22 @@ export class Select extends React.Component { simpleValue, checkAllBySearch, labelField, - valueField + valueField, + filterOption = defaultFilterOption } = this.props; + const inputValue = this.state.inputValue; let {selection} = this.state; let filtedOptions: Array