Skip to content

Commit c0b51f5

Browse files
niyapilhan007
authored andcommitted
feat(ui5-multicombobox): introduce open property and openChange event (#930)
1 parent 0489673 commit c0b51f5

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

packages/main/src/MultiComboBox.js

+28
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ const metadata = {
122122
type: Boolean,
123123
},
124124

125+
/**
126+
* Indicates whether the dropdown is open. True if the dropdown is open, false otherwise.
127+
*
128+
* @type {boolean}
129+
* @defaultvalue false
130+
* @since 1.0.0-rc.5
131+
* @public
132+
*/
133+
open: {
134+
type: Boolean,
135+
},
136+
125137
/**
126138
* Indicates whether the input is focssed
127139
* @private
@@ -164,6 +176,15 @@ const metadata = {
164176
*/
165177
input: {},
166178

179+
/**
180+
* Fired when the dropdown is opened or closed.
181+
*
182+
* @event
183+
* @since 1.0.0-rc.5
184+
* @public
185+
*/
186+
openChange: {},
187+
167188
/**
168189
* Fired when selection is changed by user interaction
169190
* in <code>SingleSelect</code> and <code>MultiSelect</code> modes.
@@ -388,6 +409,9 @@ class MultiComboBox extends UI5Element {
388409

389410
_toggleIcon() {
390411
this._iconPressed = !this._iconPressed;
412+
this.open = this._iconPressed;
413+
414+
this.fireEvent("openChange");
391415
}
392416

393417
_getSelectedItems() {
@@ -458,6 +482,10 @@ class MultiComboBox extends UI5Element {
458482
this._filteredItems = filteredItems;
459483
}
460484

485+
onAfterRendering() {
486+
this.open && this._getPopover().openBy(this);
487+
}
488+
461489
get _tokenizer() {
462490
return this.shadowRoot.querySelector("ui5-tokenizer");
463491
}

packages/main/test/pages/MultiComboBox.html

+12-1
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,28 @@
250250
const eventParamsInput = document.getElementById("events-parameters");
251251
const callCountInput = document.getElementById("events-call-count");
252252
const resetBtn = document.getElementById("reset-btn");
253+
var selectionChangeCounter = 0;
254+
var openChangeCounter = 0;
253255

254256
document.getElementById("mcb").addEventListener("ui5-selectionChange", function (event) {
257+
selectionChangeCounter += 1;
255258
eventNameInput.value = "selectionChange";
256259
eventParamsInput.value = event.detail.items.length;
257-
callCountInput.value = parseInt(callCountInput.value) + 1;
260+
callCountInput.value = selectionChangeCounter;
261+
});
262+
263+
document.getElementById("multi1").addEventListener("ui5-openChange", function (event) {
264+
openChangeCounter += 1;
265+
eventNameInput.value = "openChange";
266+
callCountInput.value = openChangeCounter;
258267
});
259268

260269
resetBtn.addEventListener("click", function (event) {
261270
eventNameInput.value = "";
262271
eventParamsInput.value = "";
263272
callCountInput.value = "";
273+
selectionChangeCounter = 0;
274+
openChangeCounter = 0;
264275
});
265276
</script>
266277

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

+22
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ describe("MultiComboBox general interaction", () => {
1414
icon.click();
1515
assert.ok(!popover.getProperty("opened"), "Popover should close");
1616
});
17+
18+
it("MultiComboBox open property is set correctly", () => {
19+
const mcb = browser.$("#multi1");
20+
const icon = browser.$("#multi1").shadow$("[input-icon]");
21+
const eventInput = $("#events-input");
22+
const callCountInput = $("#events-call-count");
23+
const resetBtn = $("#reset-btn");
24+
25+
resetBtn.click();
26+
icon.click();
27+
assert.ok(mcb.getProperty("open"), "MultiComboBox should be opened");
28+
assert.strictEqual(eventInput.getValue(), "openChange", "openChange should be called");
29+
assert.strictEqual(callCountInput.getValue(), "1", "Event should be called once");
30+
31+
icon.click();
32+
assert.ok(!mcb.getProperty("open"), "MultiComboBox should be closed");
33+
34+
assert.strictEqual(eventInput.getValue(), "openChange", "openChange should be called");
35+
assert.strictEqual(callCountInput.getValue(), "2", "Event should be called once");
36+
37+
resetBtn.click();
38+
});
1739
});
1840

1941
describe("selection and filtering", () => {

0 commit comments

Comments
 (0)