Skip to content

Commit eca3bd6

Browse files
authored
feat(ui5-input): Support 'inactive' suggestions (#1921)
Now the Input suggestions can be from type="Inactive". Note: the inactive items can't be selected neither with the mouse, nor with the keyboard. Note: the inactive items produces empty string in the input field, when previewed with the UP/DOWN arrow keys, the same way as the group header item, as both are not selectable Related to: #1919
1 parent 0a2ff88 commit eca3bd6

File tree

6 files changed

+49
-19
lines changed

6 files changed

+49
-19
lines changed

packages/main/src/Input.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,13 @@ class Input extends UI5Element {
781781

782782
previewSuggestion(item) {
783783
this.valueBeforeItemSelection = this.value;
784-
this.value = item.group ? "" : item.textContent;
784+
785+
if (item.type === "Inactive" || item.group) {
786+
this.value = "";
787+
} else {
788+
this.value = item.textContent;
789+
}
790+
785791
this._announceSelectedItem();
786792
this._previewItem = item;
787793
}
@@ -903,10 +909,8 @@ class Input extends UI5Element {
903909

904910
onItemPreviewed(item) {
905911
this.previewSuggestion(item);
906-
const suggestionItem = this.getSuggestionByListItem(item);
907-
908912
this.fireEvent("suggestion-item-preview", {
909-
item: suggestionItem,
913+
item: this.getSuggestionByListItem(item),
910914
targetRef: item,
911915
});
912916
}

packages/main/src/InputPopover.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
icon="{{this.icon}}"
6060
description="{{this.description}}"
6161
info="{{this.info}}"
62+
type="{{this.type}}"
6263
info-state="{{this.infoState}}"
6364
@ui5-_item-press="{{ fnOnSuggestionItemPress }}"
6465
data-ui5-key="{{key}}"

packages/main/src/SuggestionItem.js

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
33
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
44
import StandardListItem from "./StandardListItem.js";
55
import GroupHeaderListItem from "./GroupHeaderListItem.js";
6+
import ListItemType from "./types/ListItemType.js";
67

78
/**
89
* @public
@@ -21,6 +22,23 @@ const metadata = {
2122
type: String,
2223
},
2324

25+
/**
26+
* Defines the visual indication and behavior of the item.
27+
* Available options are <code>Active</code> (by default), <code>Inactive</code> and <code>Detail</code>.
28+
* <br><br>
29+
* <b>Note:</b> When set to <code>Active</code>, the item will provide visual response upon press and hover,
30+
* while when <code>Inactive</code> or <code>Detail</code> - will not.
31+
*
32+
* @type {ListItemType}
33+
* @defaultvalue "Active"
34+
* @public
35+
* @since 1.0.0-rc.8
36+
*/
37+
type: {
38+
type: ListItemType,
39+
defaultValue: ListItemType.Active,
40+
},
41+
2442
/**
2543
* Defines the description displayed right under the item text, if such is present.
2644
* @type {string}

packages/main/src/features/InputSuggestions.js

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Suggestions {
5353
description: suggestion.description || undefined,
5454
image: suggestion.image || undefined,
5555
icon: suggestion.icon || undefined,
56+
type: suggestion.type || undefined,
5657
info: suggestion.info || undefined,
5758
infoState: suggestion.infoState,
5859
group: suggestion.group,
@@ -146,6 +147,12 @@ class Suggestions {
146147
itemText: item.textContent,
147148
};
148149

150+
// If the item is "Inactive", prevent selection with SPACE or ENTER
151+
// to have consistency with the way "Inactive" items behave in the ui5-list
152+
if (item.type === "Inactive") {
153+
return;
154+
}
155+
149156
this._getComponent().onItemSelected(this._getRealItems()[this.selectedItemIndex], keyboardUsed);
150157
item.selected = false;
151158
this.close();

packages/main/test/pages/Input.html

+12-13
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ <h3>Input suggestions with ui5-li</h3>
8888
<ui5-li>Cozy</ui5-li>
8989
<ui5-li>Compact</ui5-li>
9090
<ui5-li>Condensed</ui5-li>
91-
<ui5-li>Cozy</ui5-li>
92-
<ui5-li>Compact</ui5-li>
93-
<ui5-li>Condensed</ui5-li>
91+
<ui5-li type="Inactive">Inactive Compact</ui5-li>
92+
<ui5-li type="Inactive">Inactive Condensed</ui5-li>
9493
</ui5-input>
9594
<br/>
9695
<br/>
@@ -101,8 +100,8 @@ <h3>Input suggestions with grouping</h3>
101100
<ui5-suggestion-item text="Condensed"></ui5-suggestion-item>
102101
<ui5-suggestion-item text="Cozy"></ui5-suggestion-item>
103102
<ui5-suggestion-item group text="Themes"></ui5-suggestion-item>
104-
<ui5-suggestion-item text="Quartz"></ui5-suggestion-item>
105-
<ui5-suggestion-item text="HCB"></ui5-suggestion-item>
103+
<ui5-suggestion-item type="Inactive" text="Inactive Quartz"></ui5-suggestion-item>
104+
<ui5-suggestion-item type="Inactive" text="Inactive HCB"></ui5-suggestion-item>
106105
</ui5-input>
107106

108107
<h3> Input disabled</h3>
@@ -450,23 +449,23 @@ <h3>Test ariaLabel and ariaLabelledBy</h3>
450449
el.addEventListener("mouseover", function (event) {
451450
const targetRef = event.detail.targetRef;
452451
quickViewCard.close();
453-
quickViewCard.openBy(item, true /* preventInitialFocus */, false /* closeWithOpener */);
452+
quickViewCard.openBy(targetRef, true /* preventInitialFocus */, false /* closeWithOpener */);
454453

455454
// log info
456455
mouseoverResult.value = targetRef.textContent;
457456
console.log("mouseover");
458457
});
459458

460459
el.addEventListener("mouseout", function (event) {
461-
if (!focusQuickView) {
462-
quickViewCard.close(false, false, true);
463-
}
460+
// if (!focusQuickView) {
461+
// quickViewCard.close(false, false, true);
462+
// }
464463

465-
focusQuickView = false;
464+
// focusQuickView = false;
466465

467-
// log info
468-
mouseoutResult.value = event.detail.targetRef.textContent;
469-
console.log("mouseout");
466+
// // log info
467+
// mouseoutResult.value = event.detail.targetRef.textContent;
468+
// console.log("mouseout");
470469
});
471470
});
472471

packages/main/test/specs/Input.spec.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,12 @@ describe("Input general interaction", () => {
217217
suggestionsInput.keys("c"); // to open the suggestions pop up once again
218218
suggestionsInput.keys("ArrowUp");
219219

220-
assert.strictEqual(suggestionsInput.getValue(), "Condensed", "First item has been selected");
220+
assert.strictEqual(suggestionsInput.getValue(), "",
221+
"The Last item 'Inactive Condensed' has been selected, producing empty string as 'Inactive'");
221222

222223
inputResult.click();
223224

224-
assert.strictEqual(inputResult.getValue(), "1", "suggestionItemSelect is fired once");
225+
assert.strictEqual(inputResult.getValue(), "1", "suggestionItemSelect is not fired as item is 'Inactive'");
225226
});
226227

227228
it("handles group suggestion item via keyboard", () => {

0 commit comments

Comments
 (0)