-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat(InputField): support recommendedMaxLength prop for display-only errors #1771
Conversation
Codecov Report
@@ Coverage Diff @@
## next #1771 +/- ##
==========================================
+ Coverage 92.29% 92.35% +0.06%
==========================================
Files 146 147 +1
Lines 2635 2656 +21
Branches 697 711 +14
==========================================
+ Hits 2432 2453 +21
Misses 187 187
Partials 16 16
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
2ef640e
to
44715bb
Compare
44715bb
to
ff085ef
Compare
ff085ef
to
b73aaa9
Compare
const textExceedsMaxLength = | ||
maxLength !== undefined && fieldLength ? fieldLength > maxLength : false; |
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.
Nit, couple ideas:
const fieldLength = fieldText?.toString().length ?? 0;
const textExceedsMaxLength = maxLength && fieldLength > maxLength;
or give maxLength
a default and simplifyt the check even more
maxLength = Infinity
...
const textExceedsMaxLength = fieldLength > maxLength;
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.
Will apply a few things where possible. One thing I wanted to avoid were any props being added if the consumer didn't specify them. maxLength
is also weird in that it changes how the base field behaves when it has a value, and it treats Infinity
as invalid if it gets to <textarea>
); | ||
|
||
// Pick the smallest of the lengths to set as the maximum value allowed | ||
const maxLengthShown = getMinValue(maxLength, recommendedMaxLength); |
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 maxLength
and recommendedMaxLength
are numbers (e.g. if they have default values or fallbacks), may be able to use Math.min
?
…errors - allow handling for maxlength and recommendedMaxLength like TextareaField - add utility method for finding smallest value - update snapshots and tests
b73aaa9
to
612bad2
Compare
size-limit report 📦
|
## [13.4.0](v13.3.0...v13.4.0) (2023-10-03) ### Features * **Accordion:** allow empty or hidden accordion rows ([#1767](#1767)) ([e044a85](e044a85)) * **Icons:** allow component icon usages to be headless ([#1761](#1761)) ([ba454bf](ba454bf)) * **InputField:** support recommendedMaxLength prop for display-only errors ([#1771](#1771)) ([cc84a20](cc84a20)) * **Tabs:** add ability to customize tab button headers ([#1768](#1768)) ([f231ad4](f231ad4)) * **TextareaField:** support recommendedMaxLength prop for display-only errors ([#1769](#1769)) ([0852356](0852356))
Summary:
maxlength
andrecommendedMaxLength
like TextareaFieldTest Plan:
edu-stack
ortraject
as a sanity check if changes affect build or deploy, or are breaking, such as token changes, widely used component updates, hooks changes, and major dependency upgrades.