-
Notifications
You must be signed in to change notification settings - Fork 57
Focus on first invalid field for wizard #1836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,8 @@ | |
|
|
||
| constructor(params) { | ||
| super(params); | ||
| const {element} = params; | ||
| const {element, formContainer} = params; | ||
| this.formContainer = formContainer; | ||
| this.cacheElements(element); | ||
| this.setActive(this.getCachedTabs()) | ||
| this._active = this.getActiveIndex(this.getCachedTabs()); | ||
|
|
@@ -232,6 +233,8 @@ | |
| if (tabs && nextVisibleIndex >= 0) { | ||
| this.#navigateAndFocusTab(nextVisibleIndex); | ||
| } | ||
| } else { | ||
| this.formContainer.setFocus(validationErrorList[0].fieldName); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No null guard on this.formContainer?.setFocus(validationErrorList[0].fieldName); |
||
| } | ||
| this.#hideUnhideNavButtons(this._active); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,6 +223,20 @@ describe("Form with Wizard Layout Container With Validation", () => { | |
| }) | ||
| }) | ||
| }); | ||
|
|
||
| it("should stay on current tab and show validation errors when next is clicked with invalid fields", () => { | ||
| getTabs().should('have.length', 5); | ||
| getWizardPanels().should('have.length', 5); | ||
| getTabAtIndex(0).should('have.class', 'cmp-adaptiveform-wizard__tab--active'); | ||
| getWizardPanelAtIndex(0).should('have.class', 'cmp-adaptiveform-wizard__wizardpanel--active'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test verifies the tab stays active and error messages appear, but the main new behavior — that focus moves to the first invalid field — is not asserted. The // verify focus landed on the first invalid field
cy.focused().closest('[data-cmp-is]').should('have.attr', 'data-cmp-is');or checking |
||
|
|
||
| getNextButton().click({force: true}).then(() => { | ||
| getTabAtIndex(0).should('have.class', 'cmp-adaptiveform-wizard__tab--active'); | ||
| getWizardPanelAtIndex(0).should('have.class', 'cmp-adaptiveform-wizard__wizardpanel--active'); | ||
| getWizardPanelAtIndex(0).find('.cmp-adaptiveform-numberinput__errormessage').should('be.visible'); | ||
| getWizardPanelAtIndex(0).find('.cmp-adaptiveform-datepicker__errormessage').should('be.visible'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Form with Wizard Layout Container with focus", () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formContaineris stored here but never guarded before use. If any caller constructs the wizard view without passingformContainerin params (e.g. a subclass, test harness, or future refactor),this.formContainerwill beundefinedand thesetFocuscall in#navigateToNextTabwill throw. Consider either asserting it is present here (if (!formContainer) console.warn(...)) or using optional chaining at the call site.