Skip to content

Commit

Permalink
feat(ui5-mcb): introduces filter property (#2088)
Browse files Browse the repository at this point in the history
Build-in filters are

 - StartsWithPerTerm
 - StartsWith
 - Contains
 - None

Users can now set filter to None and filter when input event is fired

FIXES: #799
  • Loading branch information
MapTo0 authored Nov 17, 2020
1 parent 03abf00 commit 03cae4b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
9 changes: 8 additions & 1 deletion packages/main/src/ComboBoxFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ const Contains = (value, items) => {
});
};

export { StartsWithPerTerm, StartsWith, Contains };
const None = (_, items) => items;

export {
StartsWithPerTerm,
StartsWith,
Contains,
None,
};
23 changes: 17 additions & 6 deletions packages/main/src/MultiComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import ResponsivePopover from "./ResponsivePopover.js";
import List from "./List.js";
import StandardListItem from "./StandardListItem.js";
import ToggleButton from "./ToggleButton.js";
import * as Filters from "./ComboBoxFilters.js";
import Button from "./Button.js";

import {
VALUE_STATE_SUCCESS,
VALUE_STATE_ERROR,
Expand Down Expand Up @@ -201,6 +203,19 @@ const metadata = {
type: Boolean,
},

/**
* Defines the filter type of the <code>ui5-multi-combobox</code>.
* Available options are: <code>StartsWithPerTerm</code>, <code>None</code>.
*
* @type {string}
* @defaultvalue "StartsWithPerTerm"
* @public
*/
filter: {
type: String,
defaultValue: "StartsWithPerTerm",
},

/**
* Indicates whether the dropdown is open. True if the dropdown is open, false otherwise.
*
Expand Down Expand Up @@ -586,12 +601,8 @@ class MultiComboBox extends UI5Element {
}
}

_filterItems(value) {
return this.items.filter(item => {
return item.text
&& item.text.toLowerCase().startsWith(value.toLowerCase())
&& (this.filterSelected ? item.selected : true);
});
_filterItems(str) {
return (Filters[this.filter] || Filters.StartsWithPerTerm)(str, this.items);
}

_toggle() {
Expand Down

0 comments on commit 03cae4b

Please sign in to comment.