From e39d41f286194c30df7e03542bc015d1013f244d Mon Sep 17 00:00:00 2001 From: Kyrylo Hudym-Levkovych Date: Thu, 20 Jun 2024 05:42:04 +0300 Subject: [PATCH] fix: username suggestions alignment --- .../UsernameField/UsernameField.jsx | 21 +++++++++++-------- src/register/data/sagas.js | 15 ++++++++++--- src/sass/_registration.scss | 18 +++++++--------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/register/RegistrationFields/UsernameField/UsernameField.jsx b/src/register/RegistrationFields/UsernameField/UsernameField.jsx index 59d077c62b..8ebccde33a 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 0325cd4bec..779d6ec21f 100644 --- a/src/register/data/sagas.js +++ b/src/register/data/sagas.js @@ -1,11 +1,14 @@ import { camelCaseObject } from '@edx/frontend-platform'; import { logError, logInfo } from '@edx/frontend-platform/logging'; -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, @@ -41,9 +44,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 && e.response.status === 403) { yield put(fetchRealtimeValidationsFailure()); diff --git a/src/sass/_registration.scss b/src/sass/_registration.scss index 75889601c8..e95d89d4ec 100644 --- a/src/sass/_registration.scss +++ b/src/sass/_registration.scss @@ -65,22 +65,20 @@ margin-right: 0.25rem; } -.username-suggestions { +.username__form-group-wrapper { position: relative; - margin-top: -2.5rem; - margin-left: 15px; } -.username-suggestions__close__button { - right: 1rem; +.username-suggestions { position: absolute; + inset: 0; + padding-left: 15px; + z-index: 100; } -.username-suggestions__error { - position: relative; - margin-top: -13.7%; - margin-bottom: 11%; - margin-left: 15px; +.username-suggestions__close__button { + right: 1rem; + position: absolute; } .username-scroll-suggested--form-field {