-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OptionsSelector display max length error with counter when exceeded #28722
Conversation
# Conflicts: # src/components/OptionsSelector/BaseOptionsSelector.js
@allroundexperts Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
updateSearchValue(value) { | ||
if (value.length > this.props.maxLength) { | ||
this.setState({ | ||
searchValue: value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we setting the searchValue
here and not calling onChangeText
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not calling it causes the following behaviour:
Screen.Recording.2023-10-05.at.1.05.28.AM.mov
Notice how the options keep on showing despite no results existing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following should work well:
updateSearchValue(value) {
this.setState({
searchValue: value,
errorMessage: value.length > this.props.maxLength ? this.props.translate('common.error.characterLimitExceedCounter', {length: value.length, limit: this.props.maxLength}) : '',
});
this.props.onChangeText(value);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@allroundexperts
Calling this.props.onChangeText(value)
will display the result for exceeded search value.
If we are going to allow that, I will remove searchValue
also, because this.props.value
it always updated when onChange
and will used in the TextInput instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahmedGaber93 I think showing the results for the exceeded search value is fine. As long as we're allowing the user to enter the new value, we should also use it for showing the results. As such, the following works better:
updateSearchValue(value) {
this.setState({
searchValue: value,
errorMessage: value.length > this.props.maxLength ? this.props.translate('common.error.characterLimitExceedCounter', {length: value.length, limit: this.props.maxLength}) : '',
});
this.props.onChangeText(value);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@allroundexperts
I added searchValue
to get the length of search text, because I was stopped calling this.props.onChangeText
after exceed and the length of this.props.value
is stopped, and now we will always use this.props.onChangeText
, so I removed searchValue
and back using this.props.value
.
I will update it to be
updateSearchValue(value) {
this.setState({
errorMessage: value.length > this.props.maxLength ? this.props.translate('common.error.characterLimitExceedCounter', {length: value.length, limit: this.props.maxLength}) : '',
});
this.props.onChangeText(value);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Thanks!
Reviewer Checklist
Screenshots/VideosWebScreen.Recording.2023-10-05.at.1.02.10.AM.movMobile Web - ChromeScreen.Recording.2023-10-05.at.1.11.00.AM.movMobile Web - SafariScreen.Recording.2023-10-05.at.1.08.26.AM.movDesktopScreen.Recording.2023-10-05.at.1.03.48.AM.moviOSScreen.Recording.2023-10-05.at.1.07.49.AM.movAndroidScreen.Recording.2023-10-05.at.1.09.09.AM.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small change needed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
onSubmitEditing={this.selectFocusedOption} | ||
placeholder={this.props.placeholderText} | ||
maxLength={this.props.maxLength} | ||
maxLength={this.props.maxLength + CONST.ERROR_EXCEED_RANGE} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused, can you explain this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flodnv
We decide to use the below design.
We will allow the user to type more than the maxLength, but we will display an error with counter like the image below, and adding upper bound that stops the input.
So the input maxLength
should be maxLength + the range we will display the exceeded counter
E.g. maxLength = 500 + 20 will show the error from 501 to 520

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. maxLength = 500 + 20 will show the error from 501 to 520
Sorry I am not seeing what that means on your screenshot 😕 What do you mean by "will show the error from 501 to 520"? What and where will the "501 to 520" error show? 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flodnv
Sorry about wrong screenshot, this is the correct screenshot.
// the length can user type it without see the error with counter in the scrrenshot above.
this.props.maxLength = 500;
// the range we will display the error from 501 to 520
CONST.ERROR_EXCEED_RANGE = 20;
// so the max length that user can type at all and the input will allow it will be
maxLength={this.props.maxLength + CONST.ERROR_EXCEED_RANGE}
501 to 520 mean when the typed text length is between 501 and 520 characters, the error with counter will be displayed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if I understand this correctly, it is impossible to type past 520 chars? What if I paste 1000 chars there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we paste 1000 char, it will paste only 520 char, because the input maxLength don't let it accept more than 520 char, and this is the default behavior for maxLength, you can try here
There are conflicts 😞 |
# Conflicts: # src/CONST.ts
@flodnv conflict is resolved. |
# Conflicts: # src/CONST.ts
@flodnv other conflict is occurred and is now resolved. |
I am awaiting your reply here: #28722 (comment) |
src/CONST.ts
Outdated
@@ -2737,6 +2737,8 @@ const CONST = { | |||
}, | |||
|
|||
MISSING_TRANSLATION: 'MISSING TRANSLATION', | |||
SEARCH_MAX_LENGTH: 500, | |||
ERROR_EXCEED_RANGE: 20, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERROR_EXCEED_RANGE: 20, | |
/** | |
* The count of characters we'll allow the user to type after reaching SEARCH_MAX_LENGTH in an input. | |
*/ | |
ADDITIONAL_ALLOWED_CHARACTERS: 20, |
Thanks! Now that I understand what this is, I can suggest what I think is a better name along with some nice docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the comment makes it more understandable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about renaming the variable itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, correct, I missed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flodnv updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@flodnv Updated! |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.3.83-11 🚀
|
2 similar comments
🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.3.83-11 🚀
|
🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.3.83-11 🚀
|
🚀 Deployed to production by https://github.com/jasperhuangg in version: 1.3.83-11 🚀
|
Details
Fixed Issues
$ #25804
PROPOSAL: #25804 (comment)
Tests
Offline tests
N/A.
QA Steps
Same as Tests step.
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
Screen.Recording.2023-10-03.at.12.34.04.PM.mov
Mobile Web - Chrome
Screen.Recording.2023-10-03.at.1.40.30.PM.mov
Mobile Web - Safari
Screen.Recording.2023-10-03.at.1.02.26.PM.mov
Desktop
Screen.Recording.2023-10-03.at.12.39.02.PM.mov
iOS
Screen.Recording.2023-10-03.at.12.43.32.PM.mov
Android
Screen.Recording.2023-10-03.at.1.37.16.PM.mov