-
Notifications
You must be signed in to change notification settings - Fork 1k
USWDS - Validation: Allow textareas to use validation (Enhancement) #5233
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
Conversation
Thanks for this submission! I have tagged this for review and we will take a look at our next available opportunity. If you have any questions in the meantime, please let us know! |

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.
@danbrady thanks for the contribution, but I'm not sure I understand the problem.
Based on this comment:
However, textarea is a form element in which validation might be desired (e.g. not empty, minimal number of characters or words.)
This could be solved by using character count. Could you provide a more specific use case?
Good question, @mejiaj. Is it fair to think character count is validation for a single, specific requirement? (I.e. cannot be more than N characters.) From the docs:
(Admittedly, this is probably the most useful validation for a However, allowing The use cases are likely rare, but are not non-existent. |
aafc952
to
68f29da
Compare

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 as far as extending the functionality to textarea. Just some comments below.
<label class="usa-label" for="comment">Comment</label> | ||
<textarea class="usa-textarea" id="comment" name="comment" data-validate-empty="\S" data-validation-element="validate-comment"></textarea> | ||
<input class="usa-button" type="submit" value="Submit comment"> | ||
</fieldset> |
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.
Can we separate these tests, one for input and another for text area?
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.
Should we add a test that mentions initialization on textarea?
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.
Agreed. I'll separate textarea
into separate story, test, etc. and add this to it instead of mixing it up with input
. I'll update the PR...
73aad4b
to
5ed5f75
Compare
ccdd95d
to
0b4aa55
Compare
Ok, @mejiaj, I split textarea out. A few observations when looking at the tests on the original
I don't see an element with that uswds/packages/usa-validation/src/test/validator.spec.js Lines 47 to 53 in 18e6480
uswds/packages/usa-validation/src/test/validator.spec.js Lines 37 to 39 in 18e6480
(It's looking for the validators within the Amazingly, all the test pass! You can even change all the asserts to anything and it still passes. 😄 I addressed all these in the |
Thanks for making these changes and apologies for the late reply. Data checklist label
Looks like a regression. This was introduced in #4914. Looks like in rework it was removed in commit c284450, but the test wasn't updated. Thanks for catching. Unit testsValidation list items
Yes, that looks incorrect. Incorrect validators
This should fix this. Validators are set in list items and should be checked there. It's also a good callout for improving our testing, thank you. @thisisdano @amyleadem I've removed data from this PR and set that in the original issue instead. Because of the additional work involved, we should move this to 3.8.0. |
Created issue for the additional work #5756. Todo
|
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.
Component, stories, and tests look good! Left two comments for potential future enhancements for the team.
CC: @amyleadem @mejiaj
const VALIDATE_INPUT = | ||
"input[data-validation-element],textarea[data-validation-element]"; |
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.
Validate input selector
Curious if there is a slightly cleaner way to define this selector. Probably not a blocker because this works well but may be room for a future enhancement in the future 🤔
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.
Validation Alert: Defined width (future enhancement)
Currently, the validation alert matches the size of the input it's tied to. With text area, users can resize the text box using the corner of the input and it causes the alert to grow with it.
I'm curious if it'd be a good idea to set a max width on the alert or to limit the text area to only extend vertically. Flagging for consideration!
Kapture.2024-02-05.at.17.21.47.webm
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 don't mind this behavior, actually, but that might just be personal preference. Happy to discuss this as a possible future change if desired. I don't think it needs to be a blocker for this PR.
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 to me!
Here is what I tested:
- Confirm that the validation component works with
textarea
elements - Confirm that a new story for the
textarea
variant exists and works as expected - Confirm unit tests work as expected
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.
LGTM
It looks like the changes here may have introduced an accessibility build failure which is causing other pull requests to fail. Edit: See fix at #5795
|
Summary
Textarea components can use validation Now you can use validation on textareas, just like you do on inputs.
Breaking change
This is not a breaking change.
Related issue
Closes #4702
Problem statement
Currently, validation can only be used on
input
elements. This solves most validation needs. However,textarea
is a form element in which validation might be desired (e.g. not empty, minimal number of characters or words.)Solution
input[data-validation-element]
textarea[data-validation-element]
Testing and review
Share recommended methods for reviewing this change.
textarea
to testsDependency updates
None.