From b2bd2295b8b65af19142ca97e5c65d94a0d38e1d Mon Sep 17 00:00:00 2001 From: Adeel Khan Date: Wed, 17 Mar 2021 18:20:42 +0500 Subject: [PATCH] Adds aria-invalid to fields. This would enable screen readers to readout fields errors to users. VAN-387 --- .../AuthnValidationFormGroup.jsx | 3 +++ src/forgot-password/ForgotPasswordPage.jsx | 1 + .../ForgotPasswordPage.test.jsx.snap | 3 +++ src/login/LoginPage.jsx | 2 ++ .../__snapshots__/LoginPage.test.jsx.snap | 10 ++++++++++ src/register/RegistrationPage.jsx | 5 +++++ .../RegistrationPage.test.jsx.snap | 18 ++++++++++++++++++ src/reset-password/ResetPasswordPage.jsx | 2 ++ .../ResetPasswordPage.test.jsx.snap | 8 ++++++++ 9 files changed, 52 insertions(+) diff --git a/src/common-components/AuthnValidationFormGroup.jsx b/src/common-components/AuthnValidationFormGroup.jsx index 9a6bebc5..97f9c4ae 100644 --- a/src/common-components/AuthnValidationFormGroup.jsx +++ b/src/common-components/AuthnValidationFormGroup.jsx @@ -62,6 +62,7 @@ const AuthnCustomValidationFormGroup = (props) => { type: props.type, value: props.value, className: props.inputFieldStyle, + 'aria-invalid': props.ariaInvalid, }; inputProps.onChange = (e) => onChangeHandler(e, onChange); inputProps.onClick = (e) => onClickHandler(e, onClick); @@ -112,6 +113,7 @@ AuthnCustomValidationFormGroup.defaultProps = { type: '', value: '', invalid: false, + ariaInvalid: false, invalidMessage: '', inputFieldStyle: '', helpText: '', @@ -134,6 +136,7 @@ AuthnCustomValidationFormGroup.propTypes = { PropTypes.bool, ]), invalid: PropTypes.bool, + ariaInvalid: PropTypes.bool, invalidMessage: PropTypes.string, helpText: PropTypes.string, className: PropTypes.string, diff --git a/src/forgot-password/ForgotPasswordPage.jsx b/src/forgot-password/ForgotPasswordPage.jsx index 4a1f5ff1..6e13b100 100644 --- a/src/forgot-password/ForgotPasswordPage.jsx +++ b/src/forgot-password/ForgotPasswordPage.jsx @@ -110,6 +110,7 @@ const ForgotPasswordPage = (props) => { name="email" type="email" invalid={validationError !== ''} + ariaInvalid={validationError !== ''} invalidMessage={validationError} value={values.email} onBlur={() => getValidationMessage(values.email)} diff --git a/src/forgot-password/tests/__snapshots__/ForgotPasswordPage.test.jsx.snap b/src/forgot-password/tests/__snapshots__/ForgotPasswordPage.test.jsx.snap index d711d3c3..05844318 100644 --- a/src/forgot-password/tests/__snapshots__/ForgotPasswordPage.test.jsx.snap +++ b/src/forgot-password/tests/__snapshots__/ForgotPasswordPage.test.jsx.snap @@ -31,6 +31,7 @@ exports[`ForgotPasswordPage should match default section snapshot 1`] = ` this.setState({ password: e.target.value, isSubmitted: false })} diff --git a/src/login/tests/__snapshots__/LoginPage.test.jsx.snap b/src/login/tests/__snapshots__/LoginPage.test.jsx.snap index 65766837..599b2124 100644 --- a/src/login/tests/__snapshots__/LoginPage.test.jsx.snap +++ b/src/login/tests/__snapshots__/LoginPage.test.jsx.snap @@ -44,6 +44,7 @@ exports[`LoginPage should match TPA provider snapshot 1`] = ` this.handleOnBlur(e)} @@ -487,6 +488,7 @@ class RegistrationPage extends React.Component { type="text" className="data-hj-suppress" invalid={this.state.errors.username !== ''} + ariaInvalid={this.state.errors.username !== ''} invalidMessage={this.state.errors.username} value={this.state.username} onBlur={(e) => this.handleOnBlur(e)} @@ -501,6 +503,7 @@ class RegistrationPage extends React.Component { type="text" className="data-hj-suppress" invalid={this.state.errors.email !== ''} + ariaInvalid={this.state.errors.email !== ''} invalidMessage={this.state.errors.email} value={this.state.email} onBlur={(e) => this.handleOnBlur(e)} @@ -515,6 +518,7 @@ class RegistrationPage extends React.Component { name="password" type="password" invalid={this.state.errors.password !== ''} + ariaInvalid={this.state.errors.password !== ''} invalidMessage={this.state.errors.password} value={this.state.password} onBlur={(e) => this.handleOnBlur(e)} @@ -530,6 +534,7 @@ class RegistrationPage extends React.Component { type="select" key="country" invalid={this.state.errors.country !== ''} + ariaInvalid={this.state.errors.country !== ''} invalidMessage={intl.formatMessage(messages['country.validation.message'])} className="mb-0 data-hj-suppress" value={this.state.country} diff --git a/src/register/tests/__snapshots__/RegistrationPage.test.jsx.snap b/src/register/tests/__snapshots__/RegistrationPage.test.jsx.snap index 6c2eeb81..94825074 100644 --- a/src/register/tests/__snapshots__/RegistrationPage.test.jsx.snap +++ b/src/register/tests/__snapshots__/RegistrationPage.test.jsx.snap @@ -43,6 +43,7 @@ exports[`RegistrationPageTests should match TPA provider snapshot 1`] = ` { name="new-password1" type="password" invalid={!passwordValid} + ariaInvalid={!passwordValid} invalidMessage={validationMessage} value={newPasswordInput} onChange={e => handleNewPasswordChange(e)} @@ -166,6 +167,7 @@ const ResetPasswordPage = (props) => { name="new-password2" type="password" invalid={!passwordMatch} + ariaInvalid={!passwordMatch} invalidMessage={intl.formatMessage(messages['reset.password.page.invalid.match.message'])} value={confirmPasswordInput} onChange={e => handleConfirmPasswordChange(e)} diff --git a/src/reset-password/tests/__snapshots__/ResetPasswordPage.test.jsx.snap b/src/reset-password/tests/__snapshots__/ResetPasswordPage.test.jsx.snap index 8fdbd559..7f675b3a 100644 --- a/src/reset-password/tests/__snapshots__/ResetPasswordPage.test.jsx.snap +++ b/src/reset-password/tests/__snapshots__/ResetPasswordPage.test.jsx.snap @@ -32,6 +32,7 @@ exports[`ResetPasswordPage should match invalid token message section snapshot 1