Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui5-input): introduce new SuggestionGroupItem #3248

Merged
merged 5 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
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
31 changes: 24 additions & 7 deletions packages/main/src/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,34 @@ const metadata = {
},

/**
* Defines the component suggestion items.
* Defines the suggestion items.
* <br><br>
* Example:
* <br><br>
* &lt;ui5-input show-suggestions><br>
* &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-suggestion-item text="Item #1">&lt;/ui5-suggestion-item><br>
* &nbsp;&nbsp;&nbsp;&nbsp;&lt;ui5-suggestion-item text="Item #2">&lt;/ui5-suggestion-item><br>
* &lt;/ui5-input>
* <br>
* <ui5-input show-suggestions>
* <ui5-suggestion-group-item text="Group #1"></ui5-suggestion-group-item>
* <ui5-suggestion-item text="Item #1"></ui5-suggestion-item>
* <ui5-suggestion-item text="Item #2"></ui5-suggestion-item>
* <ui5-suggestion-group-item text="Group #2"></ui5-suggestion-group-item>
* <ui5-suggestion-item text="Item #3"></ui5-suggestion-item>
* <ui5-suggestion-item text="Item #4"></ui5-suggestion-item>
* </ui5-input>
* <br><br>
* <b>Note:</b> The suggestion would be displayed only if the <code>showSuggestions</code>
* property is set to <code>true</code>.
* <br><br>
* <b>Note:</b> The &lt;ui5-suggestion-item> is recommended to be used as a suggestion item.
* Importing the Input Suggestions Support feature:
* <b>Note:</b> The &lt;ui5-suggestion-item> and &lt;ui5-suggestion-group-item> are recommended to be used as suggestion items.
* <br><br>
* <b>Note:</b> Importing the Input Suggestions Support feature:
* <br>
* <code>import "@ui5/webcomponents/dist/features/InputSuggestions.js";</code>
* <br>
* also automatically imports the &lt;ui5-suggestion-item> for your convenience.
* automatically imports the &lt;ui5-suggestion-item> and &lt;ui5-suggestion-group-item> for your convenience.
*
* @type {sap.ui.webcomponents.main.IInputSuggestionItem[]}
* @slot suggestionItems
Expand Down Expand Up @@ -261,8 +278,8 @@ const metadata = {
/**
* Defines whether the component should show suggestions, if such are present.
* <br><br>
* <b>Note:</b>
* Don`t forget to import the <code>InputSuggestions</code> module from <code>"@ui5/webcomponents/dist/features/InputSuggestions.js"</code> to enable this functionality.
* <b>Note:</b> You need to import the <code>InputSuggestions</code> module
* from <code>"@ui5/webcomponents/dist/features/InputSuggestions.js"</code> to enable this functionality.
* @type {boolean}
* @defaultvalue false
* @public
Expand Down Expand Up @@ -441,7 +458,7 @@ const metadata = {
* @alias sap.ui.webcomponents.main.Input
* @extends sap.ui.webcomponents.base.UI5Element
* @tagname ui5-input
* @appenddocs SuggestionItem
* @appenddocs SuggestionItem SuggestionGroupItem
* @implements sap.ui.webcomponents.main.IInput
* @public
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/InputPopover.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
{{#*inline "suggestionsList"}}
<ui5-list separators="{{suggestionSeparators}}">
{{#each suggestionsTexts}}
{{#if group}}
{{#if groupItem}}
<ui5-li-groupheader data-ui5-key="{{key}}">{{{ this.text }}}</ui5-li-groupheader>
{{else}}
<ui5-li-suggestion-item
Expand Down
64 changes: 64 additions & 0 deletions packages/main/src/SuggestionGroupItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import GroupHeaderListItem from "./GroupHeaderListItem.js";

/**
* @public
*/
const metadata = {
tag: "ui5-suggestion-group-item",
properties: /** @lends sap.ui.webcomponents.main.SuggestionGroupItem.prototype */ {
/**
* Defines the text of the <code>ui5-suggestion-group-item</code>.
*
* @type {string}
* @defaultvalue ""
* @public
*/
text: {
type: String,
},
},
slots: /** @lends sap.ui.webcomponents.main.SuggestionGroupItem.prototype */ {
},
events: /** @lends sap.ui.webcomponents.main.SuggestionGroupItem.prototype */ {
},
};

/**
* @class
* The <code>ui5-suggestion-group-item</code> is type of suggestion item,
* that can be used to split the <code>ui5-input</code> suggestions into groups.
*
* @constructor
* @author SAP SE
* @alias sap.ui.webcomponents.main.SuggestionGroupItem
* @extends UI5Element
* @tagname ui5-suggestion-group-item
* @implements sap.ui.webcomponents.main.IInputSuggestionItem
* @public
* @since 1.0.0-rc.15
*/
class SuggestionItem extends UI5Element {
static get metadata() {
return metadata;
}

static get dependencies() {
return [
GroupHeaderListItem,
];
}

/**
* Indicates the "grouping" nature of the component
* to avoid tag name checks tag name to diferenciate from the standard suggestion item.
* @protected
*/
get groupItem() {
return true;
}
}

SuggestionItem.define();

export default SuggestionItem;
16 changes: 0 additions & 16 deletions packages/main/src/SuggestionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";

import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
import SuggestionListItem from "./SuggestionListItem.js";
import GroupHeaderListItem from "./GroupHeaderListItem.js";
import ListItemType from "./types/ListItemType.js";

/**
Expand Down Expand Up @@ -111,20 +110,6 @@ const metadata = {
type: ValueState,
defaultValue: ValueState.None,
},

/**
* Defines the item to be displayed as a group item.
* <br><br>
* <b>Note:</b>
* When set, the other properties, such as <code>image</code>, <code>icon</code>, <code>description</code>, etc. will be omitted
* and only the <code>text</code> will be displayed.
* @type {boolean}
* @defaultvalue false
* @public
*/
group: {
type: Boolean,
},
},
slots: /** @lends sap.ui.webcomponents.main.SuggestionItem.prototype */ {
},
Expand Down Expand Up @@ -152,7 +137,6 @@ class SuggestionItem extends UI5Element {
static get dependencies() {
return [
SuggestionListItem,
GroupHeaderListItem,
];
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/main/src/features/InputSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import List from "../List.js";
import ResponsivePopover from "../ResponsivePopover.js";
import SuggestionItem from "../SuggestionItem.js";
import SuggestionGroupItem from "../SuggestionGroupItem.js";
import Button from "../Button.js";
import GroupHeaderListItem from "../GroupHeaderListItem.js";
import SuggestionListItem from "../SuggestionListItem.js";
Expand Down Expand Up @@ -66,7 +67,7 @@ class Suggestions {
type: suggestion.type || undefined,
additionalText: suggestion.additionalText || undefined,
additionalTextState: suggestion.additionalTextState,
group: suggestion.group,
groupItem: suggestion.groupItem,
key: idx,
});
});
Expand Down Expand Up @@ -416,6 +417,7 @@ class Suggestions {
static get dependencies() {
return [
SuggestionItem,
SuggestionGroupItem,
ResponsivePopover,
List,
SuggestionListItem,
Expand Down
31 changes: 20 additions & 11 deletions packages/main/test/pages/Input.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ <h3>Input suggestions with ui5-li</h3>
<br/>
<h3>Input suggestions with grouping</h3>
<ui5-input id="myInputGrouping" show-suggestions style="width: 100%">
<ui5-suggestion-item group text="Content Density"></ui5-suggestion-item>
<ui5-suggestion-group-item text="Content Density"></ui5-suggestion-group-item>
<ui5-suggestion-item text="Compact"></ui5-suggestion-item>
<ui5-suggestion-item text="Condensed"></ui5-suggestion-item>
<ui5-suggestion-item text="Cozy"></ui5-suggestion-item>
<ui5-suggestion-item group text="Themes"></ui5-suggestion-item>
<ui5-suggestion-group-item text="Themes"></ui5-suggestion-group-item>
<ui5-suggestion-item type="Inactive" text="Inactive Quartz"></ui5-suggestion-item>
<ui5-suggestion-item type="Inactive" text="Inactive HCB"></ui5-suggestion-item>
</ui5-input>
Expand Down Expand Up @@ -390,15 +390,24 @@ <h3>Test Backspace</h3>
}

suggestionItems.forEach(function(item, idx) {
var suggestion = document.createElement("ui5-suggestion-item");
suggestion.id = item.key;
suggestion.icon = "world";
suggestion.additionalText = "explore";
suggestion.group = item.text.length === 1;
suggestion.additionalTextState = "Success";
suggestion.description = "travel the world";
suggestion.text = item.text
input.appendChild(suggestion);
let suggestion;
const groupItem = item.text.length === 1;

if (groupItem) {
suggestion = document.createElement("ui5-suggestion-group-item");
suggestion.id = item.key;
suggestion.text = item.text;
input.appendChild(suggestion);
} else {
suggestion = document.createElement("ui5-suggestion-item");
suggestion.id = item.key;
suggestion.icon = "world";
suggestion.description = "travel the world";
suggestion.text = item.text
suggestion.additionalText = "explore";
suggestion.additionalTextState = "Success";
input.appendChild(suggestion);
}
});

labelLiveChange.innerHTML = "Event [input] :: " + value;
Expand Down