Skip to content

Commit

Permalink
fix(ui5-multi-combobox): Fix value reset on ESC (#3958)
Browse files Browse the repository at this point in the history
* Clear value on ESC

* Always reset value if custom value is not allowed

* Linting

* Remove the value removal on focusout - it will be fixed with another pull-request

* Test updates

* Retrigger the build
  • Loading branch information
ndeshev authored Sep 27, 2021
1 parent a64eaf8 commit ed128db
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/main/src/MultiComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isSpace,
isLeft,
isRight,
isEscape,
isEnter,
} from "@ui5/webcomponents-base/dist/Keys.js";
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
Expand Down Expand Up @@ -588,6 +589,11 @@ class MultiComboBox extends UI5Element {
this._tokenizer._focusLastToken();
}

// Reset value on ESC
if (isEscape(event) && (!this.allowCustomValues || (!this.open && this.allowCustomValues))) {
this.value = this._lastValue;
}

if (isEnter(event)) {
this.handleEnter();
}
Expand Down Expand Up @@ -845,6 +851,8 @@ class MultiComboBox extends UI5Element {
} else {
this._innerInput.blur();
}

this._lastValue = this.value;
}

inputFocusOut(event) {
Expand Down
35 changes: 35 additions & 0 deletions packages/main/test/specs/MultiComboBox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,41 @@ describe("MultiComboBox general interaction", () => {
assert.strictEqual(tokens.length, 2, "2 tokens are visible");
});

it ("Value should be reset on ESC key", async () => {
await browser.url(`http://localhost:${PORT}/test-resources/pages/MultiComboBox.html`);

const mCombo = await browser.$("#another-mcb");
const mCombo2 = await browser.$("#more-mcb");
const input = await mCombo.shadow$("#ui5-multi-combobox-input");
const input2 = await mCombo2.shadow$("#ui5-multi-combobox-input");

await input.click();
await input.keys("C");
await input.keys("Escape");
await input.keys("Escape");

assert.strictEqual(await mCombo.getProperty("value"), "", "Value should be reset to the initial one");

await input.click();
await input.keys("C");

// Move focus to another element and bring it back
await input2.click();
await input.click();

await input.keys("o");
await input.keys("Escape");
await input.keys("Escape");

assert.strictEqual(await mCombo.getProperty("value"), "C", "Value should be reset to the initial one");

await input2.click();
await input2.keys("C");
await input2.keys("Escape");

assert.strictEqual(await mCombo2.getProperty("value"), "", "Value should be cleared on escape even if the suggesitons are openjed");
});

it ("selects an item when enter is pressed and value matches a text of an item in the list", async () => {
await browser.url(`http://localhost:${PORT}/test-resources/pages/MultiComboBox.html`);

Expand Down

0 comments on commit ed128db

Please sign in to comment.