-
Notifications
You must be signed in to change notification settings - Fork 1.1k
USWDS - Input Mask: Fix input mask for nested inputs #5518
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
USWDS - Input Mask: Fix input mask for nested inputs #5518
Conversation
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 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>
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.
Great simple fix! This work allowed me to implement error states that previously caused an error in #5879
Very cool to see such a minor change have some positive downstream impact. Thanks for sharing! |
Thank you! |
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
)