Skip to content

Commit 1e0be4e

Browse files
khudymKyrylo Hudym-Levkovych
and
Kyrylo Hudym-Levkovych
authored
fix: username suggestions alignment (#1278)
Co-authored-by: Kyrylo Hudym-Levkovych <[email protected]>
1 parent 8b21603 commit 1e0be4e

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

src/register/RegistrationFields/UsernameField/UsernameField.jsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const UsernameField = (props) => {
100100
};
101101

102102
const suggestedUsernames = () => (
103-
<div className={className}>
103+
<div className={className} role="listbox">
104104
<span className="text-gray username-suggestion--label">{formatMessage(messages['registration.username.suggestion.label'])}</span>
105105
<div className="username-scroll-suggested--form-field">
106106
{usernameSuggestions.map((username, index) => (
@@ -111,7 +111,9 @@ const UsernameField = (props) => {
111111
className="username-suggestions--chip data-hj-suppress"
112112
autoComplete={props.autoComplete}
113113
key={`suggestion-${index.toString()}`}
114+
tabIndex={0}
114115
onClick={(e) => handleSuggestionClick(e, username)}
116+
role="option"
115117
>
116118
{username}
117119
</Button>
@@ -122,7 +124,7 @@ const UsernameField = (props) => {
122124
);
123125

124126
if (usernameSuggestions.length > 0 && errorMessage && value === ' ') {
125-
className = 'username-suggestions__error';
127+
className = 'username-suggestions';
126128
iconButton = <IconButton src={Close} iconAs={Icon} alt="Close" onClick={() => handleUsernameSuggestionClose()} variant="black" size="sm" className="username-suggestions__close__button" />;
127129
suggestedUsernameDiv = suggestedUsernames();
128130
} else if (usernameSuggestions.length > 0 && value === ' ') {
@@ -133,14 +135,15 @@ const UsernameField = (props) => {
133135
suggestedUsernameDiv = suggestedUsernames();
134136
}
135137
return (
136-
<FormGroup
137-
{...props}
138-
handleChange={handleOnChange}
139-
handleFocus={handleOnFocus}
140-
handleBlur={handleOnBlur}
141-
>
138+
<div className="username__form-group-wrapper">
142139
{suggestedUsernameDiv}
143-
</FormGroup>
140+
<FormGroup
141+
{...props}
142+
handleChange={handleOnChange}
143+
handleFocus={handleOnFocus}
144+
handleBlur={handleOnBlur}
145+
/>
146+
</div>
144147
);
145148
};
146149

src/register/data/sagas.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { camelCaseObject } from '@edx/frontend-platform';
22
import { logError, logInfo } from '@edx/frontend-platform/logging';
3-
import { call, put, takeEvery } from 'redux-saga/effects';
3+
import {
4+
call, put, race, take, takeEvery,
5+
} from 'redux-saga/effects';
46

57
import {
68
fetchRealtimeValidationsBegin,
79
fetchRealtimeValidationsFailure,
810
fetchRealtimeValidationsSuccess,
11+
REGISTER_CLEAR_USERNAME_SUGGESTIONS,
912
REGISTER_FORM_VALIDATIONS,
1013
REGISTER_NEW_USER,
1114
registerNewUserBegin,
@@ -41,9 +44,15 @@ export function* handleNewUserRegistration(action) {
4144
export function* fetchRealtimeValidations(action) {
4245
try {
4346
yield put(fetchRealtimeValidationsBegin());
44-
const { fieldValidations } = yield call(getFieldsValidations, action.payload.formPayload);
4547

46-
yield put(fetchRealtimeValidationsSuccess(camelCaseObject(fieldValidations)));
48+
const { response } = yield race({
49+
response: call(getFieldsValidations, action.payload.formPayload),
50+
cancel: take(REGISTER_CLEAR_USERNAME_SUGGESTIONS),
51+
});
52+
53+
if (response) {
54+
yield put(fetchRealtimeValidationsSuccess(camelCaseObject(response.fieldValidations)));
55+
}
4756
} catch (e) {
4857
if (e.response && e.response.status === 403) {
4958
yield put(fetchRealtimeValidationsFailure());

src/sass/_registration.scss

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,20 @@
6565
margin-right: 0.25rem;
6666
}
6767

68-
.username-suggestions {
68+
.username__form-group-wrapper {
6969
position: relative;
70-
margin-top: -2.5rem;
71-
margin-left: 15px;
7270
}
7371

74-
.username-suggestions__close__button {
75-
right: 1rem;
72+
.username-suggestions {
7673
position: absolute;
74+
inset: 0;
75+
padding-left: 15px;
76+
z-index: 100;
7777
}
7878

79-
.username-suggestions__error {
80-
position: relative;
81-
margin-top: -13.7%;
82-
margin-bottom: 11%;
83-
margin-left: 15px;
79+
.username-suggestions__close__button {
80+
right: 1rem;
81+
position: absolute;
8482
}
8583

8684
.username-scroll-suggested--form-field {

0 commit comments

Comments
 (0)