Skip to content

Commit 03cae4b

Browse files
authored
feat(ui5-mcb): introduces filter property (#2088)
Build-in filters are - StartsWithPerTerm - StartsWith - Contains - None Users can now set filter to None and filter when input event is fired FIXES: #799
1 parent 03abf00 commit 03cae4b

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

packages/main/src/ComboBoxFilters.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ const Contains = (value, items) => {
3030
});
3131
};
3232

33-
export { StartsWithPerTerm, StartsWith, Contains };
33+
const None = (_, items) => items;
34+
35+
export {
36+
StartsWithPerTerm,
37+
StartsWith,
38+
Contains,
39+
None,
40+
};

packages/main/src/MultiComboBox.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import ResponsivePopover from "./ResponsivePopover.js";
2424
import List from "./List.js";
2525
import StandardListItem from "./StandardListItem.js";
2626
import ToggleButton from "./ToggleButton.js";
27+
import * as Filters from "./ComboBoxFilters.js";
2728
import Button from "./Button.js";
29+
2830
import {
2931
VALUE_STATE_SUCCESS,
3032
VALUE_STATE_ERROR,
@@ -201,6 +203,19 @@ const metadata = {
201203
type: Boolean,
202204
},
203205

206+
/**
207+
* Defines the filter type of the <code>ui5-multi-combobox</code>.
208+
* Available options are: <code>StartsWithPerTerm</code>, <code>None</code>.
209+
*
210+
* @type {string}
211+
* @defaultvalue "StartsWithPerTerm"
212+
* @public
213+
*/
214+
filter: {
215+
type: String,
216+
defaultValue: "StartsWithPerTerm",
217+
},
218+
204219
/**
205220
* Indicates whether the dropdown is open. True if the dropdown is open, false otherwise.
206221
*
@@ -586,12 +601,8 @@ class MultiComboBox extends UI5Element {
586601
}
587602
}
588603

589-
_filterItems(value) {
590-
return this.items.filter(item => {
591-
return item.text
592-
&& item.text.toLowerCase().startsWith(value.toLowerCase())
593-
&& (this.filterSelected ? item.selected : true);
594-
});
604+
_filterItems(str) {
605+
return (Filters[this.filter] || Filters.StartsWithPerTerm)(str, this.items);
595606
}
596607

597608
_toggle() {

0 commit comments

Comments
 (0)