Skip to content

Commit ba10757

Browse files
feat(ui5-wizard): add getFocusDomRef (#12668)
1 parent 4ce5617 commit ba10757

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

packages/fiori/cypress/specs/Wizard.cy.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,4 +633,76 @@ describe("Wizard inside Dialog", () => {
633633
.find("[ui5-responsive-popover]")
634634
.should("be.visible");
635635
});
636+
});
637+
638+
describe("Wizard - getFocusDomRef Method", () => {
639+
it("should focus the last focused wizard tab on wizard focus", () => {
640+
const onButtonClick = () => {
641+
document.getElementById("wizard").focus();
642+
}
643+
cy.mount(
644+
<>
645+
<Wizard id="wizard">
646+
<WizardStep icon="sap-icon://product" titleText="Product type">
647+
<MessageStrip>
648+
The Wizard control is supposed to break down large tasks.
649+
</MessageStrip>
650+
</WizardStep>
651+
<WizardStep titleText="Product Information" selected />
652+
<WizardStep titleText="Product Text" />
653+
</Wizard>
654+
<Button>Dummy Btn</Button>
655+
<Button onClick={onButtonClick}>Focus Wizard</Button>
656+
</>
657+
);
658+
659+
cy.get("[ui5-wizard]")
660+
.shadow()
661+
.find("[ui5-wizard-tab]")
662+
.eq(2)
663+
.realClick();
664+
665+
cy.get("[ui5-button]")
666+
.eq(0)
667+
.realClick();
668+
669+
cy.get("[ui5-button]")
670+
.eq(1)
671+
.realClick();
672+
673+
cy.get("[ui5-wizard]")
674+
.shadow()
675+
.find("[ui5-wizard-tab]")
676+
.eq(2)
677+
.shadow()
678+
.find(".ui5-wiz-step-root")
679+
.should("be.focused");
680+
});
681+
682+
it("should focus the first wizard tab if no tab was focused before ", () => {
683+
const onButtonClick = () => {
684+
document.getElementById("wizard").focus();
685+
}
686+
cy.mount(
687+
<>
688+
<Wizard id="wizard">
689+
<WizardStep icon="sap-icon://product" titleText="Product type"></WizardStep>
690+
<WizardStep titleText="Product Information" />
691+
<WizardStep titleText="Product Text" />
692+
</Wizard>
693+
<Button onClick={onButtonClick}>Focus Wizard</Button>
694+
</>
695+
);
696+
697+
cy.get("[ui5-button]")
698+
.realClick();
699+
700+
cy.get("[ui5-wizard]")
701+
.shadow()
702+
.find("[ui5-wizard-tab]")
703+
.eq(0)
704+
.shadow()
705+
.find(".ui5-wiz-step-root")
706+
.should("be.focused");
707+
});
636708
});

packages/fiori/src/Wizard.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ class Wizard extends UI5Element {
694694
return contentHeight;
695695
}
696696

697+
getFocusDomRef() {
698+
return this._itemNavigation._getCurrentItem();
699+
}
700+
697701
getStepAriaLabelText(step: WizardStep, ariaLabel: string) {
698702
return Wizard.i18nBundle.getText(WIZARD_STEP_ARIA_LABEL, ariaLabel);
699703
}

0 commit comments

Comments
 (0)