From 03cae4b4e10e0f3bcb2da9f28b87be6e1f7c6838 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 17 Nov 2020 14:24:36 +0200 Subject: [PATCH] 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: https://github.com/SAP/ui5-webcomponents/issues/799 --- packages/main/src/ComboBoxFilters.js | 9 ++++++++- packages/main/src/MultiComboBox.js | 23 +++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/main/src/ComboBoxFilters.js b/packages/main/src/ComboBoxFilters.js index 10e640969fff..8a8e3679fe0b 100644 --- a/packages/main/src/ComboBoxFilters.js +++ b/packages/main/src/ComboBoxFilters.js @@ -30,4 +30,11 @@ const Contains = (value, items) => { }); }; -export { StartsWithPerTerm, StartsWith, Contains }; +const None = (_, items) => items; + +export { + StartsWithPerTerm, + StartsWith, + Contains, + None, +}; diff --git a/packages/main/src/MultiComboBox.js b/packages/main/src/MultiComboBox.js index 149c8902f892..71f53c852437 100644 --- a/packages/main/src/MultiComboBox.js +++ b/packages/main/src/MultiComboBox.js @@ -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, @@ -201,6 +203,19 @@ const metadata = { type: Boolean, }, + /** + * Defines the filter type of the ui5-multi-combobox. + * Available options are: StartsWithPerTerm, None. + * + * @type {string} + * @defaultvalue "StartsWithPerTerm" + * @public + */ + filter: { + type: String, + defaultValue: "StartsWithPerTerm", + }, + /** * Indicates whether the dropdown is open. True if the dropdown is open, false otherwise. * @@ -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() {