Skip to content

Commit df13dc6

Browse files
Kyrylo Hudym-Levkovychihor-romaniuk
Kyrylo Hudym-Levkovych
authored andcommitted
fix: username suggestions alignment
1 parent 52c6efc commit df13dc6

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
@@ -101,7 +101,7 @@ const UsernameField = (props) => {
101101
};
102102

103103
const suggestedUsernames = () => (
104-
<div className={className}>
104+
<div className={className} role="listbox">
105105
<span className="text-gray username-suggestion--label">{formatMessage(messages['registration.username.suggestion.label'])}</span>
106106
<div className="username-scroll-suggested--form-field">
107107
{usernameSuggestions.map((username, index) => (
@@ -112,7 +112,9 @@ const UsernameField = (props) => {
112112
className="username-suggestions--chip data-hj-suppress"
113113
autoComplete={props.autoComplete}
114114
key={`suggestion-${index.toString()}`}
115+
tabIndex={0}
115116
onClick={(e) => handleSuggestionClick(e, username)}
117+
role="option"
116118
>
117119
{username}
118120
</Button>
@@ -123,7 +125,7 @@ const UsernameField = (props) => {
123125
);
124126

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

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)