Skip to content

Commit 7ad94d2

Browse files
authored
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 6d47d68 commit 7ad94d2

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

packages/fiori/src/Wizard.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ const metadata = {
122122
* @event sap.ui.webcomponents.fiori.Wizard#selection-change
123123
* @param {HTMLElement} selectedStep the newly selected step
124124
* @param {HTMLElement} previouslySelectedStep the previously selected step
125+
* @param {Boolean} changeWithClick the selection changed due to user's click on step within the navigation
125126
* @public
126127
*/
127128
"selection-change": {
128129
detail: {
129130
selectedStep: { type: HTMLElement },
130131
previouslySelectedStep: { type: HTMLElement },
132+
changeWithClick: { Boolean },
131133
},
132134
},
133135
},
@@ -593,7 +595,7 @@ class Wizard extends UI5Element {
593595
const selectedStep = this.selectedStep;
594596
const newlySelectedIndex = this.slottedSteps.indexOf(stepToSelect);
595597

596-
this.switchSelectionFromOldToNewStep(selectedStep, stepToSelect, newlySelectedIndex);
598+
this.switchSelectionFromOldToNewStep(selectedStep, stepToSelect, newlySelectedIndex, true);
597599
this._closeRespPopover();
598600
tabs[newlySelectedIndex].focus();
599601
}
@@ -626,7 +628,8 @@ class Wizard extends UI5Element {
626628
// change selection and fire "selection-change".
627629
if (newlySelectedIndex >= 0 && newlySelectedIndex <= this.stepsCount - 1) {
628630
const stepToSelect = this.slottedSteps[newlySelectedIndex];
629-
this.switchSelectionFromOldToNewStep(this.selectedStep, stepToSelect, newlySelectedIndex);
631+
632+
this.switchSelectionFromOldToNewStep(this.selectedStep, stepToSelect, newlySelectedIndex, false);
630633
this.selectionRequestedByScroll = true;
631634
}
632635
}
@@ -654,7 +657,7 @@ class Wizard extends UI5Element {
654657

655658
if (bExpanded || (!bExpanded && (newlySelectedIndex === 0 || newlySelectedIndex === this.steps.length - 1))) {
656659
// Change selection and fire "selection-change".
657-
this.switchSelectionFromOldToNewStep(selectedStep, stepToSelect, newlySelectedIndex);
660+
this.switchSelectionFromOldToNewStep(selectedStep, stepToSelect, newlySelectedIndex, true);
658661
}
659662
}
660663

@@ -925,16 +928,18 @@ class Wizard extends UI5Element {
925928
* @param {HTMLElement} selectedStep the old step
926929
* @param {HTMLElement} stepToSelect the step to be selected
927930
* @param {Integer} stepToSelectIndex the index of the newly selected step
931+
* @param {Boolean} changeWithClick the selection changed due to user click in the step navigation
928932
* @private
929933
*/
930-
switchSelectionFromOldToNewStep(selectedStep, stepToSelect, stepToSelectIndex) {
934+
switchSelectionFromOldToNewStep(selectedStep, stepToSelect, stepToSelectIndex, changeWithClick) {
931935
if (selectedStep && stepToSelect) {
932936
selectedStep.selected = false;
933937
stepToSelect.selected = true;
934938

935939
this.fireEvent("selection-change", {
936940
selectedStep: stepToSelect,
937941
previouslySelectedStep: selectedStep,
942+
changeWithClick,
938943
});
939944

940945
this.selectedStepIndex = stepToSelectIndex;

packages/fiori/test/pages/Wizard_test.html

+4-1
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("ui5-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

+9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe("Wizard general interaction", () => {
5353
const step1InHeader = wiz.shadow$(`[data-ui5-index="1"]`);
5454
const step2InHeader = wiz.shadow$(`[data-ui5-index="2"]`);
5555
const inpSelectionChangeCounter = browser.$("#inpSelectionChangeCounter");
56+
const inpSelectionChangeCause = browser.$("#inpSelectionChangeCause");
5657

5758
// act - click on the first step in the header
5859
step1InHeader.click();
@@ -76,6 +77,9 @@ describe("Wizard general interaction", () => {
7677
// assert - selection-change fired once
7778
assert.strictEqual(inpSelectionChangeCounter.getProperty("value"), "1",
7879
"Event selection-change fired once.");
80+
// assert - selection-change fired due to user click
81+
assert.strictEqual(inpSelectionChangeCause.getProperty("value"), "true",
82+
"Event selection-change fired due to click.");
7983
});
8084

8185
it("move to next step by SPACE/ENTER", () => {
@@ -139,6 +143,7 @@ describe("Wizard general interaction", () => {
139143
const step2 = browser.$("#st2");
140144
const step2InHeader = wiz.shadow$(`[data-ui5-index="2"]`);
141145
const inpSelectionChangeCounter = browser.$("#inpSelectionChangeCounter");
146+
const inpSelectionChangeCause = browser.$("#inpSelectionChangeCause");
142147

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

155160
assert.strictEqual(inpSelectionChangeCounter.getProperty("value"), "4",
156161
"Event selection-change fired 4th time due to scrolling.");
162+
163+
// assert - selection-change fired not becasue of user click
164+
assert.strictEqual(inpSelectionChangeCause.getProperty("value"), "false",
165+
"Event selection-change fired not becasue of user click, but scrolling");
157166
});
158167

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

0 commit comments

Comments
 (0)