Skip to content

Commit 0505017

Browse files
committed
feat(ui5-wizard): add parameter to selectionChange event (#3034)
For certain cases, it is useful to provide info if the selection-change is fired due to user's click on a step within the step navigation (as the selection might also occur due to scrolling). For that, we are introducing a new event parameter, called changeWithClick. The parameter would be true, whenever the event is due to user click on a step within the step navigation header, and false when fired due to user scrolling.
1 parent a2f63e9 commit 0505017

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

packages/fiori/src/Wizard.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,14 @@ const metadata = {
123123
* @event sap.ui.webcomponents.fiori.Wizard#selection-change
124124
* @param {HTMLElement} selectedStep the newly selected step
125125
* @param {HTMLElement} previouslySelectedStep the previously selected step
126+
* @param {Boolean} changeWithClick the selection changed due to user's click on step within the navigation
126127
* @public
127128
*/
128129
"selection-change": {
129130
detail: {
130131
selectedStep: { type: HTMLElement },
131132
previouslySelectedStep: { type: HTMLElement },
133+
changeWithClick: { Boolean },
132134
},
133135
},
134136
},
@@ -585,7 +587,7 @@ class Wizard extends UI5Element {
585587
const selectedStep = this.selectedStep;
586588
const newlySelectedIndex = this.slottedSteps.indexOf(stepToSelect);
587589

588-
this.switchSelectionFromOldToNewStep(selectedStep, stepToSelect, newlySelectedIndex);
590+
this.switchSelectionFromOldToNewStep(selectedStep, stepToSelect, newlySelectedIndex, true);
589591
this._closeRespPopover();
590592
tabs[newlySelectedIndex].focus();
591593
}
@@ -617,7 +619,8 @@ class Wizard extends UI5Element {
617619
// change selection and fire "selection-change".
618620
if (newlySelectedIndex >= 0 && newlySelectedIndex <= this.stepsCount - 1) {
619621
const stepToSelect = this.slottedSteps[newlySelectedIndex];
620-
this.switchSelectionFromOldToNewStep(this.selectedStep, stepToSelect, newlySelectedIndex);
622+
623+
this.switchSelectionFromOldToNewStep(this.selectedStep, stepToSelect, newlySelectedIndex, false);
621624
this.selectionRequestedByScroll = true;
622625
}
623626
}
@@ -645,7 +648,7 @@ class Wizard extends UI5Element {
645648

646649
if (bExpanded || (!bExpanded && (newlySelectedIndex === 0 || newlySelectedIndex === this.steps.length - 1))) {
647650
// Change selection and fire "selection-change".
648-
this.switchSelectionFromOldToNewStep(selectedStep, stepToSelect, newlySelectedIndex);
651+
this.switchSelectionFromOldToNewStep(selectedStep, stepToSelect, newlySelectedIndex, true);
649652
}
650653
}
651654

@@ -916,16 +919,18 @@ class Wizard extends UI5Element {
916919
* @param {HTMLElement} selectedStep the old step
917920
* @param {HTMLElement} stepToSelect the step to be selected
918921
* @param {Integer} stepToSelectIndex the index of the newly selected step
922+
* @param {Boolean} changeWithClick the selection changed due to user click in the step navigation
919923
* @private
920924
*/
921-
switchSelectionFromOldToNewStep(selectedStep, stepToSelect, stepToSelectIndex) {
925+
switchSelectionFromOldToNewStep(selectedStep, stepToSelect, stepToSelectIndex, changeWithClick) {
922926
if (selectedStep && stepToSelect) {
923927
selectedStep.selected = false;
924928
stepToSelect.selected = true;
925929

926930
this.fireEvent("selection-change", {
927931
selectedStep: stepToSelect,
928932
previouslySelectedStep: selectedStep,
933+
changeWithClick,
929934
});
930935

931936
this.selectedStepIndex = stepToSelectIndex;

packages/fiori/test/pages/Wizard_test.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
Integer pellentesque leo sit amet dui vehicula, quis ullamcorper est pulvinar. Nam in libero sem. Suspendisse arcu metus, molestie a turpis a, molestie aliquet dui. Donec ppellentesque leo sit amet dui vehicula, quis ullamcorper est pulvinar. Nam in libero sem. Suspendisse arcu metus, molestie a turpis a, molestie aliquet dui. Donec pulvinar, sapien corper eu, posuere malesuada nisl. Integer pellentesque leo sit amet dui vehicula, quis ullamcorper est pulvinar. Nam in libero sem. Suspendisse arcu metus, molestie a turpis a, molestie aliquet dui. Donec pulvinar, sapien
6666
</ui5-label>
6767

68+
<ui5-input id="inpSelectionChangeCause" placeholder="step changed via click"></ui5-input>
69+
6870
<div style="display: flex; flex-direction: column;">
6971
<div style="display: flex; flex-direction: row; justify-content: flex-end; align-items: center; margin-top: 1rem">
7072
<ui5-label>Name</ui5-label>
@@ -310,9 +312,10 @@
310312
<script>
311313
var wiz = document.getElementById("wizTest");
312314
var counter = 0;
313-
wiz.addEventListener("selection-change", function () {
315+
wiz.addEventListener("ui5-selection-change", function (event) {
314316
console.log(event.detail.selectedStep);
315317
inpSelectionChangeCounter.value = ++counter;
318+
inpSelectionChangeCause.value = event.detail.changeWithClick;
316319
});
317320

318321
toStep2.addEventListener("click", function () {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe("Wizard general interaction", () => {
5050
const step1InHeader = wiz.shadow$(`[data-ui5-index="1"]`);
5151
const step2InHeader = wiz.shadow$(`[data-ui5-index="2"]`);
5252
const inpSelectionChangeCounter = browser.$("#inpSelectionChangeCounter");
53+
const inpSelectionChangeCause = browser.$("#inpSelectionChangeCause");
5354

5455
// act - click on the first step in the header
5556
step1InHeader.click();
@@ -73,6 +74,9 @@ describe("Wizard general interaction", () => {
7374
// assert - selection-change fired once
7475
assert.strictEqual(inpSelectionChangeCounter.getProperty("value"), "1",
7576
"Event selection-change fired once.");
77+
// assert - selection-change fired due to user click
78+
assert.strictEqual(inpSelectionChangeCause.getProperty("value"), "true",
79+
"Event selection-change fired due to click.");
7680
});
7781

7882
it("move to next step by SPACE/ENTER", () => {
@@ -136,6 +140,7 @@ describe("Wizard general interaction", () => {
136140
const step2 = browser.$("#st2");
137141
const step2InHeader = wiz.shadow$(`[data-ui5-index="2"]`);
138142
const inpSelectionChangeCounter = browser.$("#inpSelectionChangeCounter");
143+
const inpSelectionChangeCause = browser.$("#inpSelectionChangeCause");
139144

140145
// act - scroll the 2nd step into view
141146
// Note: scrollIntoView works in Chrome, but if we start executing the test on every browser,
@@ -151,6 +156,10 @@ describe("Wizard general interaction", () => {
151156

152157
assert.strictEqual(inpSelectionChangeCounter.getProperty("value"), "4",
153158
"Event selection-change fired 4th time due to scrolling.");
159+
160+
// assert - selection-change fired not becasue of user click
161+
assert.strictEqual(inpSelectionChangeCause.getProperty("value"), "false",
162+
"Event selection-change fired not becasue of user click, but scrolling");
154163
});
155164

156165
it("tests dynamically increase step size and move to next step", () => {

0 commit comments

Comments
 (0)