Skip to content

Focus on first invalid field for wizard#1836

Open
rajatofficial wants to merge 4 commits intomasterfrom
FORMS-24186-InvalidFieldFocus
Open

Focus on first invalid field for wizard#1836
rajatofficial wants to merge 4 commits intomasterfrom
FORMS-24186-InvalidFieldFocus

Conversation

@rajatofficial
Copy link
Copy Markdown
Contributor

Description

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes and the overall coverage did not decrease.
  • All unit tests pass on CircleCi.
  • I ran all tests locally and they pass.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@sakshi-arora1 sakshi-arora1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test case for same

Copy link
Copy Markdown
Collaborator

@rismehta rismehta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the intent is clear and the fix makes sense. A couple of things to tighten up before merge.

constructor(params) {
super(params);
const {element} = params;
const {element, formContainer} = params;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formContainer is stored here but never guarded before use. If any caller constructs the wizard view without passing formContainer in params (e.g. a subclass, test harness, or future refactor), this.formContainer will be undefined and the setFocus call in #navigateToNextTab will throw. Consider either asserting it is present here (if (!formContainer) console.warn(...)) or using optional chaining at the call site.

this.#navigateAndFocusTab(nextVisibleIndex);
}
} else {
this.formContainer.setFocus(validationErrorList[0].fieldName);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No null guard on this.formContainer. If formContainer was not passed in params for any reason, this crashes with Cannot read properties of undefined (reading 'setFocus'). Safer as:

this.formContainer?.setFocus(validationErrorList[0].fieldName);

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');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 setFocus call is the entire point of this change. Consider adding something like:

// verify focus landed on the first invalid field
cy.focused().closest('[data-cmp-is]').should('have.attr', 'data-cmp-is');

or checking document.activeElement is within the first errored component. Without this, a regression in setFocus would not be caught by this test.

Copy link
Copy Markdown
Collaborator

@rismehta rismehta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants