diff --git a/src/register/RegistrationFields/UsernameField/UsernameField.jsx b/src/register/RegistrationFields/UsernameField/UsernameField.jsx index 8ca9f298..d1745490 100644 --- a/src/register/RegistrationFields/UsernameField/UsernameField.jsx +++ b/src/register/RegistrationFields/UsernameField/UsernameField.jsx @@ -101,7 +101,7 @@ const UsernameField = (props) => { }; const suggestedUsernames = () => ( -
+
{formatMessage(messages['registration.username.suggestion.label'])}
{usernameSuggestions.map((username, index) => ( @@ -112,7 +112,9 @@ const UsernameField = (props) => { className="username-suggestions--chip data-hj-suppress" autoComplete={props.autoComplete} key={`suggestion-${index.toString()}`} + tabIndex={0} onClick={(e) => handleSuggestionClick(e, username)} + role="option" > {username} @@ -123,7 +125,7 @@ const UsernameField = (props) => { ); if (usernameSuggestions.length > 0 && errorMessage && value === ' ') { - className = 'username-suggestions__error'; + className = 'username-suggestions'; iconButton = handleUsernameSuggestionClose()} variant="black" size="sm" className="username-suggestions__close__button" />; suggestedUsernameDiv = suggestedUsernames(); } else if (usernameSuggestions.length > 0 && value === ' ') { @@ -134,14 +136,15 @@ const UsernameField = (props) => { suggestedUsernameDiv = suggestedUsernames(); } return ( - +
{suggestedUsernameDiv} - + +
); }; diff --git a/src/register/data/sagas.js b/src/register/data/sagas.js index 120ce442..e9f6e493 100644 --- a/src/register/data/sagas.js +++ b/src/register/data/sagas.js @@ -1,10 +1,13 @@ import { camelCaseObject, logError, logInfo } from '@openedx/frontend-base'; -import { call, put, takeEvery } from 'redux-saga/effects'; +import { + call, put, race, take, takeEvery, +} from 'redux-saga/effects'; import { fetchRealtimeValidationsBegin, fetchRealtimeValidationsFailure, fetchRealtimeValidationsSuccess, + REGISTER_CLEAR_USERNAME_SUGGESTIONS, REGISTER_FORM_VALIDATIONS, REGISTER_NEW_USER, registerNewUserBegin, @@ -40,9 +43,15 @@ export function* handleNewUserRegistration(action) { export function* fetchRealtimeValidations(action) { try { yield put(fetchRealtimeValidationsBegin()); - const { fieldValidations } = yield call(getFieldsValidations, action.payload.formPayload); - yield put(fetchRealtimeValidationsSuccess(camelCaseObject(fieldValidations))); + const { response } = yield race({ + response: call(getFieldsValidations, action.payload.formPayload), + cancel: take(REGISTER_CLEAR_USERNAME_SUGGESTIONS), + }); + + if (response) { + yield put(fetchRealtimeValidationsSuccess(camelCaseObject(response.fieldValidations))); + } } catch (e) { if (e.response?.status === 403) { yield put(fetchRealtimeValidationsFailure()); diff --git a/src/sass/_registration.scss b/src/sass/_registration.scss index dc70ff1a..cc7b0e92 100644 --- a/src/sass/_registration.scss +++ b/src/sass/_registration.scss @@ -68,10 +68,15 @@ margin-right: 0.25rem; } -.username-suggestions { +.username__form-group-wrapper { position: relative; - margin-top: -2.5rem; - margin-left: 15px; +} + +.username-suggestions { + position: absolute; + inset: 0; + padding-left: 15px; + z-index: 100; } .username-suggestions__close__button { @@ -79,13 +84,6 @@ position: absolute; } -.username-suggestions__error { - position: relative; - margin-top: -13.7%; - margin-bottom: 11%; - margin-left: 15px; -} - .username-scroll-suggested--form-field { width: 20rem; white-space: nowrap;