Skip to content

Commit 359d1a3

Browse files
authored
fix(ui5-multi-combobox): display placeholder consistently (#4920)
* fix(ui5-multi-combobox): display placeholder consistently There was inconsistency when using a placeholder and programatically changing selected items. Fixes #4897
1 parent caceb7c commit 359d1a3

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

packages/main/src/MultiComboBox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ class MultiComboBox extends UI5Element {
544544
}
545545

546546
get _getPlaceholder() {
547-
if (this._tokenizer && this._tokenizer.tokens.length) {
547+
if (this._getSelectedItems().length) {
548548
return "";
549549
}
550550

packages/main/test/pages/MultiComboBox.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,25 @@ <h3>MultiComboBox in Compact</h3>
320320
<ui5-mcb-item text="Canada" additional-text="CA"></ui5-mcb-item>
321321
<ui5-mcb-item text="Chile" additional-text="CL"></ui5-mcb-item>
322322
</ui5-multi-combobox>
323+
</div>
324+
325+
<div class="demo-section">
326+
<span>Placeholder test</span>
327+
328+
<br>
329+
<ui5-button id="sel">Toggle Item</ui5-button>
330+
<ui5-multi-combobox id="mcb-init-selected-item" placeholder="Placeholder" style="width: 300px;">
331+
<ui5-mcb-item text="Item1"></ui5-mcb-item>
332+
<ui5-mcb-item selected id="mcb1" text="Initially selected"></ui5-mcb-item>
333+
</ui5-multi-combobox>
334+
<br />
335+
<br />
336+
<ui5-button id="sel2">Toggle Item</ui5-button>
337+
<ui5-multi-combobox id="mcb-init-nonselected-item" placeholder="Placeholder" style="width: 300px;">
338+
<ui5-mcb-item text="Item1"></ui5-mcb-item>
339+
<ui5-mcb-item id="mcb1_2" text="Initially not selected"></ui5-mcb-item>
340+
</ui5-multi-combobox>
341+
</div>
323342

324343
<script>
325344
var eventNameInput = document.getElementById("events-input");
@@ -349,6 +368,32 @@ <h3>MultiComboBox in Compact</h3>
349368
selectionChangeCounter = 0;
350369
openChangeCounter = 0;
351370
});
371+
372+
// Placeholders test
373+
const btn = document.getElementById("sel");
374+
const mcb1 = document.getElementById("mcb1");
375+
const btn2 = document.getElementById("sel2");
376+
const mcb1_2 = document.getElementById("mcb1_2");
377+
378+
let selected = mcb1.hasAttribute("selected");
379+
btn.addEventListener("click", () => {
380+
if (!selected) {
381+
mcb1.setAttribute("selected", selected);
382+
} else {
383+
mcb1.removeAttribute("selected");
384+
}
385+
selected = !selected;
386+
});
387+
388+
let selected2 = mcb1_2.hasAttribute("selected");
389+
btn2.addEventListener("click", () => {
390+
if (!selected2) {
391+
mcb1_2.setAttribute("selected", selected2);
392+
} else {
393+
mcb1_2.removeAttribute("selected");
394+
}
395+
selected2 = !selected2;
396+
});
352397
</script>
353398

354399
</body>

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,34 @@ describe("MultiComboBox general interaction", () => {
11781178
assert.strictEqual(await mcb2.getAttribute("placeholder"), "", "Shouldn't have placeholder when there are tokens");
11791179
});
11801180

1181+
it("placeholder tests for programatically selected items", async () => {
1182+
const innerInputSel = "#ui5-multi-combobox-input";
1183+
1184+
const mcb1 = await browser.$("#mcb-init-selected-item");
1185+
let innerInput1 = await mcb1.shadow$(innerInputSel);
1186+
const toggleItemBtn1 = await browser.$("#sel");
1187+
1188+
const mcb2 = await browser.$("#mcb-init-nonselected-item");
1189+
let innerInput2 = await mcb2.shadow$(innerInputSel);
1190+
const toggleItemBtn2 = await browser.$("#sel2");
1191+
1192+
// Preselected item
1193+
assert.strictEqual(await innerInput1.getAttribute("placeholder"), "", "Shouldn't have placeholder as there is a preselected item");
1194+
1195+
toggleItemBtn1.click();
1196+
1197+
innerInput1 = await mcb1.shadow$(innerInputSel);
1198+
assert.strictEqual(await innerInput1.getAttribute("placeholder"), "Placeholder", "Should have placeholder as the item is programatically deselected");
1199+
1200+
// No preselected item
1201+
assert.strictEqual(await innerInput2.getAttribute("placeholder"), "Placeholder", "Should have placeholder as no item is selected");
1202+
1203+
toggleItemBtn2.click();
1204+
1205+
innerInput2 = await mcb2.shadow$(innerInputSel);
1206+
assert.strictEqual(await innerInput2.getAttribute("placeholder"), "", "Shouldn't have placeholder as an item is programatically selected");
1207+
});
1208+
11811209
it ("Should not open value state message when component is in readonly state", async () => {
11821210
const mcb = await browser.$("#readonly-value-state-mcb");
11831211
const staticAreaItemClassName = await browser.getStaticAreaItemClassName("#readonly-value-state-mcb");

0 commit comments

Comments
 (0)