From 6573a6ecf318715c422617ea8ec2fa0cef62713b Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 2 Sep 2024 11:57:54 +0300 Subject: [PATCH] fix(ui5-wizard): improve focus and keyboard handling (#9758) FIXES: #9670 FIXES: #9571 --- packages/fiori/src/Wizard.hbs | 1 - packages/fiori/src/Wizard.ts | 10 ++++-- packages/fiori/src/WizardTab.hbs | 2 +- packages/fiori/src/WizardTab.ts | 16 +++++++--- packages/fiori/test/specs/Wizard.spec.js | 40 ++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 8 deletions(-) diff --git a/packages/fiori/src/Wizard.hbs b/packages/fiori/src/Wizard.hbs index 17b4c90e101b..a99dd9a37b2f 100644 --- a/packages/fiori/src/Wizard.hbs +++ b/packages/fiori/src/Wizard.hbs @@ -15,7 +15,6 @@ ._wizardTabAccInfo="{{accInfo}}" data-ui5-content-ref-id="{{this.refStepId}}" data-ui5-index="{{pos}}" - _tab-index="{{tabIndex}}" @ui5-selection-change-requested="{{../onSelectionChangeRequested}}" @ui5-focused="{{../onStepInHeaderFocused}}" @click="{{../_onGroupedTabClick}}" diff --git a/packages/fiori/src/Wizard.ts b/packages/fiori/src/Wizard.ts index 1bd9877bbe32..1e7bf7b7a626 100644 --- a/packages/fiori/src/Wizard.ts +++ b/packages/fiori/src/Wizard.ts @@ -92,7 +92,6 @@ type StepInfo = { pos: number, accInfo: AccessibilityInformation, refStepId: string, - tabIndex: string, styles: object, } @@ -409,6 +408,14 @@ class Wizard extends UI5Element { // Place for improvement: If the selected step is not the first, enable all the prior steps this.selectedStepIndex = this.getSelectedStepIndex(); + + if (this.selectedStep && this.stepsInHeaderDOM.length) { + if (this._itemNavigation._getItems().includes(this.stepsInHeaderDOM[this.selectedStepIndex])) { + this._itemNavigation.setCurrentItem(this.stepsInHeaderDOM[this.selectedStepIndex]); + } else { + this._itemNavigation.setCurrentItem(this.stepsInHeaderDOM.find(el => el.selected) as WizardTab); + } + } } /** @@ -900,7 +907,6 @@ class Wizard extends UI5Element { pos, accInfo, refStepId: step._id, - tabIndex: this.selectedStepIndex === idx ? "0" : "-1", styles: { zIndex: isAfterCurrent ? --inintialZIndex : 1, }, diff --git a/packages/fiori/src/WizardTab.hbs b/packages/fiori/src/WizardTab.hbs index 549df3e2179e..a944fd611b87 100644 --- a/packages/fiori/src/WizardTab.hbs +++ b/packages/fiori/src/WizardTab.hbs @@ -1,6 +1,6 @@
{ "Step has aria-label set to the number of the step and its title."); }); + it("Disabled step should not be interactive", async () => { + const wiz = await $("#wizTest"); + const disabledStep = await wiz.shadow$(`[data-ui5-index="2"]`); + + await disabledStep.click(); + + const isTabActiveElement = await browser.executeAsync((done) => { + done(document.activeElement.shadowRoot.activeElement === document.querySelector("#wizTest").shadowRoot.querySelector("[data-ui5-index='2']")); + }); + + assert.notOk(isTabActiveElement, "Second tab should not be active element"); + }); + it("Disabled step should not be interactive", async () => { const wiz = await browser.$("#wizTest"); const disabledStep = await wiz.shadow$(`[data-ui5-index="2"]`); @@ -325,6 +338,33 @@ describe("Wizard general interaction", () => { "No scrolling occures after re-rendering when the selected step remains the same."); }); + it("Tests if initial focus is set on the second (selected) step", async () => { + browser.url("test/pages/WizardPageMode_test.html"); + + const wiz = await browser.$("#wiz2"); + + // open the dialog + const btnOpenDialog = await browser.$("#button"); + await btnOpenDialog.click(); + + // go to second step + const step2 = await browser.$("#nextButton"); + await step2.click(); + + // close the dialog by escape + await browser.keys("Escape"); + + // open the dialog again + await btnOpenDialog.click(); + + // check if second wizard tab is focused + const isTabActiveElement = await browser.executeAsync((done) => { + done(document.activeElement.shadowRoot.activeElement === document.querySelector("#wiz2").shadowRoot.querySelector("[data-ui5-index='2']")); + }); + + assert.ok(isTabActiveElement, "Second step is focused."); + }); + it("Tests if second step is scrolled into view when first step's height is bigger than viewport", async () => { await browser.url(`test/pages/WizardScrolling.html`);