Skip to content

Commit 095d6dc

Browse files
authored
fix(ui5-select): fix use of ESC leads to wrong selection (#1724)
When the picker is closed and the user hits ESC, the component saves that action and cancels the next selection. Now ESC cancels selection only if the picker is opened. FIXES: #1721
1 parent 4b10f4f commit 095d6dc

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

packages/main/src/Select.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class Select extends UI5Element {
395395
}
396396
}
397397

398-
if (isEscape(event)) {
398+
if (isEscape(event) && this._isPickerOpen) {
399399
this._escapePressed = true;
400400
}
401401

packages/main/test/pages/Select.html

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ <h2>Selection not cycling</h2>
6060
<ui5-option>Opt3</ui5-option>
6161
</ui5-select>
6262

63+
<ui5-select id="mySelectEsc">
64+
<ui5-option>Cozy</ui5-option>
65+
<ui5-option selected>Compact</ui5-option>
66+
<ui5-option>Condensed</ui5-option>
67+
</ui5-select>
68+
6369
<h2> Change event counter holder</h2>
6470
<ui5-input id="inputResult"></ui5-input>
6571

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

+23
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,27 @@ describe("Select general interaction", () => {
228228

229229
assert.strictEqual(inputResult.getProperty("value"), "7", "Change event should be fired");
230230
});
231+
232+
it("tests ESC on closed picker", () => {
233+
const select = $("#mySelectEsc");
234+
const selectText = browser.$("#mySelectEsc").shadow$("ui5-label");
235+
const EXPECTED_SELECTION_TEXT = "Cozy";
236+
const EXPECTED_SELECTION_TEXT2 = "Condensed";
237+
238+
select.click();
239+
const staticAreaItemClassName = browser.getStaticAreaItemClassName("#mySelectEsc")
240+
const firstItem = browser.$(`.${staticAreaItemClassName}`).shadow$$("ui5-li")[0];
241+
const thirdItem = browser.$(`.${staticAreaItemClassName}`).shadow$$("ui5-li")[2];
242+
243+
firstItem.click();
244+
245+
assert.ok(selectText.getHTML(false).indexOf(EXPECTED_SELECTION_TEXT) !== -1, "Select label is correct.");
246+
247+
// verify that ESC does not interfere when the picker is closed
248+
select.keys("Escape");
249+
select.click();
250+
thirdItem.click();
251+
252+
assert.ok(selectText.getHTML(false).indexOf(EXPECTED_SELECTION_TEXT2) !== -1, "Select label is correct.");
253+
});
231254
});

0 commit comments

Comments
 (0)