Skip to content

USWDS - Bug: In-page navigation errors when heading starts with number #5199

Description

@aduth

Describe the bug

When an In-Page Navigation component includes links which start with a number, clicking on those links does not navigate to the relevant section, and instead logs a JavaScript error to the console.

Example:

Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#1-check-your-current-uswds-code-and-settings-versions-2' is not a valid selector.

This is likely related to #5068, which added the dynamically-created links based on heading content.

The reason for the error is likely due to CSS syntax restrictions, which prevent an selector ID from beginning with a number:

In CSS, identifiers (including element names, classes, and IDs in selectors) [...] cannot start with a digit, two hyphens, or a hyphen followed by a digit.

https://www.w3.org/TR/CSS2/syndata.html#value-def-identifier

Steps to reproduce the bug

  1. Go to https://designsystem.digital.gov/documentation/migration/
  2. Click a link in the In-Page Navigation

Expected Behavior

Page scrolls to the relevant section

Related code

No response

Screenshots

No response

System setup

  • USWDS version: 3.4.1
  • Operating system: macOS 12.6.3
  • Browser: Chrome Version 111.0.5563.110 (Official Build) (arm64)

Additional context

No response

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions