Skip to content

Conversation

chrislarrycarl
Copy link
Contributor

@chrislarrycarl chrislarrycarl commented Sep 27, 2023

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

  1. Rebuild the module (npm run build)
  2. Initialized a new project using the updated module (npx gulp init)
  3. Tested the same input markup that was previous broken and it worked

Copy link
Contributor

@mejiaj mejiaj left a 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>

@mejiaj mejiaj removed Needs: Confirmation We need to confirm that this is an issue Status: Triage labels Apr 15, 2024
@mejiaj mejiaj modified the milestones: uswds 3.9.0, uswds 3.8.1 Apr 17, 2024
Copy link
Contributor

@mahoneycm mahoneycm left a 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

@chrislarrycarl
Copy link
Contributor Author

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!

@thisisdano thisisdano merged commit ce79663 into uswds:develop May 22, 2024
@thisisdano
Copy link
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

USWDS - Bug: Input Mask breaks when input is not direct child of form.
5 participants