Skip to content

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

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

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

Conversation

@yogeshwaran-c

Copy link
Copy Markdown
Contributor

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
@@ -0,0 +1,26 @@
describe("a11y: API version label", () => {

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.

These e2e tests appear to be overkill; we do not check any functionality here, merely whether the component on the site exists, which is already covered by the unit test

it("should not render a <pre> element for the version label", function () {
const wrapper = mount(<VersionStamp version="1.0.0" />)

expect(wrapper.find("pre").length).toEqual(0)

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.

test should verify accessible output achieved, not just absence of one bad tag

it("should not render a <pre> element for the OAS version label", function () {
const wrapper = mount(<OpenAPIVersion oasVersion="3.0.0" />)

expect(wrapper.find("pre").length).toEqual(0)

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.

test should verify accessible output achieved, not just absence of one bad tag

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

2 participants