Skip to content

Commit 977ba80

Browse files
committed
fix(ui5-wizard): prevent scrolling to step's very top (#2888)
On re-rendering the Wizard auto scrolls to the currently selected item's top, which is useful when the step selection is changed programatically. But, when re-rendering occurs for some other reason and the step selection remains the same, the Wizard still scrolls to the top of the selected step, which is not expected. Now, this is fixed by checking if the selection has been changed. Fixes: #2883
1 parent 91d5104 commit 977ba80

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

packages/fiori/src/Wizard.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,12 @@ class Wizard extends UI5Element {
195195
// Stores references to the grouped steps.
196196
this._groupedTabs = [];
197197

198-
// Keeps track of the selected step index.
198+
// Keeps track of the currently selected step index.
199199
this.selectedStepIndex = 0;
200200

201+
// Keeps track of the previously selected step index.
202+
this.previouslySelectedStepIndex = 0;
203+
201204
// Indicates that selection will be changed
202205
// due to user click.
203206
this.selectionRequestedByClick = false;
@@ -285,8 +288,13 @@ class Wizard extends UI5Element {
285288

286289
onAfterRendering() {
287290
this.storeStepScrollOffsets();
288-
this.scrollToSelectedStep();
291+
292+
if (this.previouslySelectedStepIndex !== this.selectedStepIndex) {
293+
this.scrollToSelectedStep();
294+
}
295+
289296
this.attachStepsResizeObserver();
297+
this.previouslySelectedStepIndex = this.selectedStepIndex;
290298
}
291299

292300
/**

packages/fiori/test/specs/Wizard.spec.js

+33
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,37 @@ describe("Wizard general interaction", () => {
175175
assert.strictEqual(inpSelectionChangeCounter.getProperty("value"), "5",
176176
"Event selection-change fired once for 5th time due to scrolling.");
177177
});
178+
179+
it("tests no scrolling to selected step, if the selection was not changed", ()=>{
180+
browser.url("http://localhost:8081/test-resources/pages/Wizard_test.html");
181+
182+
const wizard = browser.$("#wizTest");
183+
const wizardContentDOM = wizard.shadow$(".ui5-wiz-content");
184+
const btnToStep2 = browser.$("#toStep2");
185+
186+
// (1) - go to step 2
187+
btnToStep2.click();
188+
189+
// (2) - scroll a bit upwards to get back to step 1 (at least its bottom part)
190+
btnToStep2.scrollIntoView();
191+
192+
// (3) store the scroll position after scrolling upwards
193+
const scrolPosBefore = browser.execute((wizardContentDOM) => {
194+
return wizardContentDOM.scrollTop
195+
}, wizardContentDOM);
196+
197+
// (4) simulate re-rendering
198+
browser.execute((wizard) => {
199+
wizard.onAfterRendering();
200+
}, wizard);
201+
202+
// (5) store the scroll position after re-rendering
203+
const scrolPosAfter = browser.execute((wizardContentDOM) => {
204+
return wizardContentDOM.scrollTop
205+
}, wizardContentDOM);
206+
207+
// assert - The Wizard did not scroll to the very top of the step 1
208+
assert.strictEqual(scrolPosBefore, scrolPosAfter,
209+
"No scrolling occures after re-rendering when the selected step remains the same.");
210+
});
178211
});

0 commit comments

Comments
 (0)