Skip to content

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

@chrislarrycarl

Description

@chrislarrycarl

Describe the bug

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.).

Steps to reproduce the bug

  1. Create a masked input where the input element is nested in any extra markup that prevents it from being a direct child of the form.
  2. Open the page the form is present on.

Expected Behavior

The input should be masked.

Related code

packages/usa-input-mask/src/index.js line 38 is currently

  input.closest(CONTEXT).insertBefore(shell, input);

but should be

input.parentNode.insertBefore(shell, input);

Screenshots

No response

System setup

  • USWDS version: 3.6.0

Additional context

This issue is resolved in Version 2, however, it's unclear when that will be released so I've submitted a stand alone PR with only this fix - sorry if this is noise.

Code of Conduct

Metadata

Metadata

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions