swagger-api / swagger-api/swagger-ui

Accessibility: Servers component nests <select> inside <label>

Open Beginner friendly
#10,957 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Describe the bug

The OpenAPI Servers component renders a <select> element nested inside a <label>:

<div class="servers">
  <label for="servers">
    <select id="servers">
      <option value="https://demo.backstage.io">https://demo.backstage.io</option>
    </select>
  </label>
</div>

This results in invalid semantic HTML and may cause accessibility issues with some screen readers.

Expected behavior

The <label> and <select> should be separate elements, for example:

<label for="servers">Servers</label>
<select id="servers">
  <option value="https://demo.backstage.io">https://demo.backstage.io</option>
</select>

This preserves the association between the label and the control while using a more conventional semantic structure.

To reproduce

  1. Open any Swagger UI instance that displays multiple or single server entries.
  2. Inspect the "Servers" dropdown in the browser's developer tools.
  3. Observe that the <select> element is rendered as a child of the <label> element.

Additional context

The markup originates from the Servers component located at:

src/core/plugins/oas3/components/servers.jsx

I discovered this while investigating an upstream issue reported in the Backstage project, which embeds Swagger UI. The Backstage maintainers confirmed that this behavior originates from Swagger UI and suggested reporting it upstream.

Related Backstage issue:
https://github.com/backstage/backstage/issues/34696

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading src/core/plugins/oas3/components/servers.jsx and inspect how the Servers component renders its label and select. Update the markup so the label and select are separate while retaining their association through the for and id attributes. Confirm that a Swagger UI instance with server entries renders the expected semantic structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
accessibility, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.