Skip to content

fix(a11y): replace <pre> with <span> for version labels#10902

Open
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/a11y-version-stamp-pre
Open

fix(a11y): replace <pre> with <span> for version labels#10902
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/a11y-version-stamp-pre

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

Description

Render the API version stamp and OAS version stamp inside <span> elements instead of <pre> so the version badges in the info block are no longer marked up as preformatted code blocks.

  • src/core/components/version-stamp.jsx<small><pre className="version">…</pre></small> -> <small><span className="version">…</span></small>
  • src/core/components/openapi-version.jsx<small class="version-stamp"><pre className="version">OAS …</pre></small> -> <span className="version">OAS …</span> inside the same <small>
  • src/style/_information.scss — descendant selector under .info .title small switched from pre to .version (the className that was already on the element) so the existing reset and text_headline typography still apply.

Motivation and Context

<pre> is reserved for preformatted blocks of computer code or ASCII figures. Wrapping a short, decorative version label in <pre> misleads assistive tech (screen readers may announce it as a code block) and was flagged in the linked issue.

Fixes #10481

How Has This Been Tested?

  • npx jest --config ./config/jest/jest.unit.config.js test/unit/components/version-stamp.jsx -> 4/4 passing. New tests assert no <pre> is rendered and the .version element still contains the version text for both <VersionStamp/> and <OpenAPIVersion/>.
  • npx cypress run --spec test/e2e-cypress/e2e/a11y/version-stamp.cy.js -> 2/2 passing against petstore-expanded.openapi.yaml. Asserts the version stamps render without a <pre> element and that the .version element still exists and is visible.
  • npx eslint on the changed JS/JSX -> clean.
  • npx stylelint src/style/_information.scss -> clean.

Screenshots

No visual change is expected — <pre> was already styled via small pre { margin:0; padding:0; … } and the matching SCSS rule was updated to .version. The badge still renders inline with the same typography and background.

Checklist

  • Bug fix
  • My code follows the code style of this project
  • My change requires a change to the documentation — No
  • I have added tests to cover my changes
  • All new and existing tests passed

Render API and OAS version stamps inside <span> elements instead of <pre>. The <pre> tag is intended for preformatted blocks of computer code, not short inline labels, so screen readers and other assistive tooling treated the version badges as code blocks.

Update the .info .title small selector to match .version (the className already on the elements) so the existing typography and reset styles continue to apply unchanged.

Fixes swagger-api#10481
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

a11y: Improper use of preformatted text elements for version labels

1 participant