Visitar URL original
USWDS-Site - Code samples: Let long code lines wrap on small screens by AKnassa · Pull Request #3302 · uswds/uswds-site · GitHub
Skip to content

USWDS-Site - Code samples: Let long code lines wrap on small screens - #3302

Merged
ryparker merged 2 commits into
uswds:mainfrom
AKnassa:ak-3293-accordion-scroll-a11y
Sep 17, 2026
Merged

ryparker merged 2 commits into
uswds:mainfrom
AKnassa:ak-3293-accordion-scroll-a11y

Conversation

@AKnassa

@AKnassa AKnassa commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Long paths and package names in code samples can overflow their containers on small screens. In the migration guide, that turns an accordion panel into a horizontally scrolling region without keyboard access.

Allow long code tokens to wrap, retaining word-wrap: break-word as a fallback. Add a mobile accessibility check that opens the affected accordion, and preserve that check when CI divides the sitemap across parallel jobs. Include the migration-page changelog entry.

Closes #3293.

Screenshots

The same migration-guide code sample at a 375px viewport:

Before After
Long code tokens overflow the code sample Long code tokens wrap within the code sample

Validation

Updated the branch from main at 922bbebe07678c205b21766a5211b76f64dd1530 and tested the combined result.

  • Full asset/Jekyll build, lint, and 37 RSpec examples passed.
  • Reproduced scrollable-region-focusable on #m-a6 with the two new CSS declarations removed: a 335px panel contained 456px of content.
  • With the fix, the expanded migration page passed axe at 375px, 320px, and 188px. The panel and its code examples no longer overflow.
  • Enter opens the accordion and Space closes it. Copied code text is unchanged.
  • The fallback passed at 375px and 188px with the newer overflow-wrap declaration removed.
  • Verified one, two, and three CI shards: all 240 configured entries remain present, including the expanded-accordion check exactly once.
  • Changelog formatting and the PR diff whitespace check passed.
  • All nine reported CI checks passed on final commit ca54fcaadcdfdd56b00d54367d609f3fd95cff1b, including full mobile and desktop accessibility scans.

At 1280px, the local expanded-page scan in current Chrome reports three header color-contrast findings with both baseline CSS and the fix. The fix introduces no additional findings in that comparison.

Review steps

Open /documentation/migration/ at a narrow viewport, expand “If you're using USWDS Gulp,” and inspect the long require(...) examples. Confirm the complete code remains visible without sideways scrolling and the accordion remains keyboard operable.

Code samples use `white-space: pre-wrap`, but nothing let a single long
token break, so a path such as
`require("./node_modules/@uswds/uswds/package.json");` ran past its
`<pre>` on small screens. The spill lands in the surrounding
`.usa-accordion__content`, which USWDS gives `overflow: auto`, so the
accordion body turns into a horizontally scrollable region. When that
region has no focusable child (no link, no copy button), axe reports
scrollable-region-focusable on it. On the migration page this hits
`#m-a6` at 375px; with browser zoom it hits every accordion in the
compiler section, including the three settings tables, whose `code`
cells could not shrink either.

Fix the cause rather than the symptom: `code, pre` get
`overflow-wrap: anywhere`, so long tokens wrap and nothing overflows the
accordion in the first place. `word-wrap: break-word` is declared first
as the fallback for browsers without `anywhere` support, which includes
the Chromium 77 that pa11y-ci's puppeteer runs. (Declaring
`overflow-wrap` twice does not survive csso, which keeps only the last
value, hence the legacy property name for the fallback.)

Add a mobile pa11y-ci entry that opens the first compiler accordion on
the migration page before scanning, mirroring the issue's steps; the
sitemap run only ever sees accordions collapsed. It fails before this
change (0/1 URLs passed, scrollable-region-focusable on #m-a6) and
passes after. The CI shard script copied only `defaults` from the base
config, which would have dropped that entry on CircleCI, so it now adds
base-config `urls` entries to the pool before sharding; each still runs
exactly once across the shards.

Verified with axe-core 4.10.2 in Chrome 153: no scrollable-region
violations on the migration page from 375px down to 188px, with and
without classic scrollbars; across all 240 sitemap pages with every
accordion opened at 375px, pages with violations go from 1 to 0. rspec,
lint, and the mobile and desktop pa11y-ci sitemap runs pass.

Fixes uswds#3293

@ryparker ryparker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the code-wrapping fix and the expanded-accordion regression check. No blocking findings.

Validated the final branch with current main merged in: full build, lint, and 37 RSpec examples pass. The baseline CSS reproduces the reported keyboard-scroll violation; the fix passes at 375px, 320px, and 188px. Keyboard open/close behavior and copied code text are preserved. The fallback also passes with the newer declaration removed, and the regression case is retained exactly once across one, two, and three CI shards.

The PR description records the unchanged desktop contrast findings separately and includes before/after screenshots.

@ryparker
ryparker merged commit 13b16c3 into uswds:main Sep 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Triage

Development

Successfully merging this pull request may close these issues.

Pa11y error thrown on accordions with specific conditions

2 participants