USWDS - Input Mask: Fix input mask for nested inputs#5518
Merged
Conversation
2 tasks
mejiaj
approved these changes
Apr 15, 2024
mejiaj
left a comment
Contributor
There was a problem hiding this comment.
Thanks for fixing this.
Looking at input mask code example you can confirm the input doesn't have a wrapper.
<form class="usa-form">
<label class="usa-label" for="ssn">Social Security Number</label>
<div class="usa-hint" id="ssnHint">For example, 123 45 6789</div>
<input
id="ssn"
inputmode="numeric"
name="ssn"
placeholder="___ __ ____"
pattern="^(?!(000|666|9))\d{3} (?!00)\d{2} (?!0000)\d{4}$"
class="usa-input usa-masked"
aria-describedby="ssnHint"
/>
</form>
This was referenced May 7, 2024
Contributor
Author
Very cool to see such a minor change have some positive downstream impact. Thanks for sharing! |
thisisdano
approved these changes
May 22, 2024
Contributor
|
Thank you! |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes span insert for masked inputs when target input is not a direct child of the form.
Breaking change
This is not a breaking change.
Related issue
Closes #5517
Related pull requests
Changelog PR →
Also resolved in Input Mask Version 2, however, it's unclear when that will be released.
Preview link
Preview link: N/A
Problem statement
The insert for the generated span to mask the input is currently targeted at the closest form
input.closest(CONTEXT).insertBefore(shell, input);which works for the example in the documentation because the input is a direct child of the form. However, when nested under any additional markup the insert fails (The node before which the new node is to be inserted is not a child of this node.).Solution
This change inserts the generated span in the input element's parent, not the closest form.
Major changes
Just a bug fix.
Testing and review
I did the following test locally
npm run build)npx gulp init)