Skip to content
Open
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
26 changes: 20 additions & 6 deletions src/multiselect/multiselect.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ const closeIconTypes = {
};

export class Multiselect extends React.Component<IMultiselectProps, any> {
static defaultProps: { options: never[]; disablePreSelectedValues: boolean; selectedValues: never[]; isObject: boolean; displayValue: string; showCheckbox: boolean; selectionLimit: number; placeholder: string; groupBy: string; style: {}; emptyRecordMsg: string; onSelect: () => void; onRemove: () => void; closeIcon: string; singleSelect: boolean; caseSensitiveSearch: boolean; id: string; closeOnSelect: boolean; avoidHighlightFirstOption: boolean; hidePlaceholder: boolean; showArrow: boolean; keepSearchTerm: boolean; };
static defaultProps: { disableFilter: boolean; customFilter: (v: any, search: string, index: number, arr: Array<any>) => boolean; options: never[]; disablePreSelectedValues: boolean; selectedValues: never[]; isObject: boolean; displayValue: string; showCheckbox: boolean; selectionLimit: number; placeholder: string; groupBy: string; style: {}; emptyRecordMsg: string; onSelect: () => void; onRemove: () => void; closeIcon: string; singleSelect: boolean; caseSensitiveSearch: boolean; id: string; closeOnSelect: boolean; avoidHighlightFirstOption: boolean; hidePlaceholder: boolean; showArrow: boolean; keepSearchTerm: boolean; };
constructor(props) {
super(props);
this.state = {
inputValue: "",
disableFilter: props.disableFilter,
options: props.options,
filteredOptions: props.options,
unfilteredOptions: props.options,
Expand Down Expand Up @@ -61,6 +62,7 @@ export class Multiselect extends React.Component<IMultiselectProps, any> {
this.getSelectedItemsCount = this.getSelectedItemsCount.bind(this);
this.hideOnClickOutside = this.hideOnClickOutside.bind(this);
this.isVisible = this.isVisible.bind(this);
this.customFilter = props?.customFilter?.bind(this);
}

initialSetValue() {
Expand Down Expand Up @@ -194,13 +196,25 @@ export class Multiselect extends React.Component<IMultiselectProps, any> {
}

filterOptionsByInput() {
let { options, filteredOptions, inputValue } = this.state;
const { isObject, displayValue } = this.props;
if (isObject) {
options = filteredOptions.filter(i => this.matchValues(i[displayValue], inputValue))
let { options, filteredOptions, inputValue, disableFilter, customFilter } = this.state;

if (disableFilter) {
this.groupByOptions(options);
this.setState({ options });
return
}

if (customFilter) {
options = filteredOptions.filter((v, i, arr) => customFilter(v, inputValue, i, arr))
} else {
options = filteredOptions.filter(i => this.matchValues(i, inputValue));
const { isObject, displayValue } = this.props;
if (isObject) {
options = filteredOptions.filter(i => this.matchValues(i[displayValue], inputValue))
} else {
options = filteredOptions.filter(i => this.matchValues(i, inputValue));
}
}

this.groupByOptions(options);
this.setState({ options });
}
Expand Down