Skip to content

Commit d46be1f

Browse files
authoredDec 17, 2019
fix(ui5-select): prevent selection from cycling (#1066)
1 parent e4ed295 commit d46be1f

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed
 

‎packages/main/src/Select.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,11 @@ class Select extends UI5Element {
363363
}
364364

365365
_getNextOptionIndex() {
366-
return this._selectedIndex === (this.options.length - 1) ? 0 : (this._selectedIndex + 1);
366+
return this._selectedIndex === (this.options.length - 1) ? this._selectedIndex : (this._selectedIndex + 1);
367367
}
368368

369369
_getPreviousOptionIndex() {
370-
return this._selectedIndex === 0 ? (this.options.length - 1) : (this._selectedIndex - 1);
370+
return this._selectedIndex === 0 ? this._selectedIndex : (this._selectedIndex - 1);
371371
}
372372

373373
_beforeOpen() {

‎packages/main/test/pages/Select.html

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ <h2>Disabled Select</h2>
4646
<h2> Input with suggestions</h2>
4747
<ui5-input id="myInput" show-suggestions placeholder="Search for a country ..."></ui5-input>
4848

49+
<h2>Selection not cycling</h2>
50+
<ui5-select id="selectionNotCycling">
51+
<ui5-option>Opt1</ui5-option>
52+
<ui5-option>Opt2</ui5-option>
53+
<ui5-option selected>Opt3</ui5-option>
54+
</ui5-select>
55+
56+
<ui5-select id="selectionNotCycling2">
57+
<ui5-option selected>Opt1</ui5-option>
58+
<ui5-option>Opt2</ui5-option>
59+
<ui5-option>Opt3</ui5-option>
60+
</ui5-select>
61+
4962
<h2> Change event counter holder</h2>
5063
<ui5-input id="inputResult"></ui5-input>
5164
</body>

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

+32-3
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,41 @@ describe("Select general interaction", () => {
7373
assert.strictEqual(inputResult.getProperty("value"), "5", "Change event should have fired twice");
7474
});
7575

76+
it("tests selection does not cycle with ArrowDown", () => {
77+
const select = $("#selectionNotCycling");
78+
const EXPECTED_SELECTION_TEXT = "Opt3";
79+
const selectOptionText = select.shadow$("ui5-label");
80+
81+
select.click();
82+
assert.ok(selectOptionText.getHTML(false).indexOf(EXPECTED_SELECTION_TEXT) > -1, "Selected option text is " + EXPECTED_SELECTION_TEXT);
83+
84+
// The last item is already selected - pressing ArrowDown should not change the focus or the selection
85+
select.keys("ArrowDown");
86+
assert.ok(selectOptionText.getHTML(false).indexOf(EXPECTED_SELECTION_TEXT) > -1, "Selected option text remains " + EXPECTED_SELECTION_TEXT);
87+
88+
// Close the select not to cover other components that tests would try to click
89+
select.keys("Escape");
90+
91+
});
92+
93+
it("tests selection does not cycle with ArrowUp", () => {
94+
const select = $("#selectionNotCycling2");
95+
const EXPECTED_SELECTION_TEXT = "Opt1";
96+
const selectOptionText = select.shadow$("ui5-label");
97+
98+
select.click();
99+
assert.ok(selectOptionText.getHTML(false).indexOf(EXPECTED_SELECTION_TEXT) > -1, "Selected option text is " + EXPECTED_SELECTION_TEXT);
100+
101+
// The last item is already selected - pressing ArrowUp should not change the focus or the selection
102+
select.keys("ArrowUp");
103+
assert.ok(selectOptionText.getHTML(false).indexOf(EXPECTED_SELECTION_TEXT) > -1, "Selected option text remains " + EXPECTED_SELECTION_TEXT);
104+
105+
// Close the select not to cover other components that tests would try to click
106+
select.keys("Escape");
107+
});
76108

77109
it("opens upon space", () => {
78110
const btn = $("#myBtn2");
79-
const select = $("#mySelect");
80111
const popover = browser.$("#mySelect").shadow$("ui5-popover");
81112

82113
btn.click();
@@ -88,7 +119,6 @@ describe("Select general interaction", () => {
88119

89120
it("toggles upon F4", () => {
90121
const btn = $("#myBtn2");
91-
const select = $("#mySelect");
92122
const popover = browser.$("#mySelect").shadow$("ui5-popover");
93123

94124
btn.click();
@@ -103,7 +133,6 @@ describe("Select general interaction", () => {
103133

104134
it("toggles upon ALT + UP", () => {
105135
const btn = $("#myBtn2");
106-
const select = $("#mySelect");
107136
const popover = browser.$("#mySelect").shadow$("ui5-popover");
108137

109138
btn.click();

0 commit comments

Comments
 (0)
Please sign in to comment.