Visitar URL original
USWDS - Character Count: Fix label selector by ealexhaywood · Pull Request #6385 · uswds/uswds · GitHub
Skip to content

USWDS - Character Count: Fix label selector - #6385

Merged
ethangardner merged 2 commits into
uswds:developfrom
ealexhaywood:fix-label-selector-for-character-count
Jun 23, 2026
Merged

ethangardner merged 2 commits into
uswds:developfrom
ealexhaywood:fix-label-selector-for-character-count

Conversation

@ealexhaywood

@ealexhaywood ealexhaywood commented Feb 7, 2025 •

Copy link
Copy Markdown
Contributor

Summary

Fix label selector query for character count component.

Breaking change

This is not a breaking change.

Related issue

Closes #6384

Problem statement

The character count component can fail if its input element ID contains characters that would make a selector query invalid.

Solution

Placing the ID in quotes in the selector query fixes this.

@jerseycheese

Copy link
Copy Markdown

Tested this against current develop. The branch here is very behind, but the one-line change cherry-picks clean and the target line is unchanged upstream, so it still applies as-is.

Reproduced the bug first: built a Character Count whose input uses a React useId()-style id (:r0:), and CharacterCount.on() throws exactly what the issue reports:

SyntaxError: 'label[for=character-count-:r0:]' is not a valid selector

With this PR's change (label[for="${inputID}"]) the same setup initializes cleanly. So the fix does what it says.

Worth flagging why this isn't an edge case: :r0: is literally what React 18+'s useId() emits, and pairing useId() across the input and its <label for> is the existing pattern. Any React/Next consumer wiring Character Count up that way hits it.

Two small things, neither a blocker:

  • Quoting handles every id that's valid HTML, which is the actual bug here. If you wanted to be bulletproof against an id containing a literal " or \, CSS.escape(inputID) is the belt-and-suspenders version, but that's beyond what's reported.

@github-actions

Copy link
Copy Markdown
Contributor

✅ All commits on this PR now have a verified signature. Thanks for making that change!

@ethangardner
ethangardner self-requested a review June 23, 2026 01:43

@ethangardner ethangardner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, and thanks for the contribution. Sorry for the looooooong delay in getting this reviewed and merged.

@ethangardner
ethangardner merged commit 166e9c1 into uswds:develop Jun 23, 2026
6 checks passed
@ethangardner ethangardner added this to the uswds 3.14.0 - Aug 2026 milestone Aug 4, 2026
@annepetersen annepetersen added the ❤️ Thanks Historical appreciation marker. Prefer a reaction; not required for triage. label Aug 5, 2026
@github-project-automation github-project-automation Bot moved this to Fed Final Review in USWDS Core Project Data Aug 21, 2026
@chandracarney chandracarney moved this from Fed Final Review to Done in USWDS Core Project Data Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

❤️ Thanks Historical appreciation marker. Prefer a reaction; not required for triage.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

USWDS - Bug: Character Count component's selector query for label's for attribute does not include quotes

4 participants